https://github.com/lukepistrol/pexels-swift
Pexels API client library for the Swift programming language.
https://github.com/lukepistrol/pexels-swift
ios macos pexels pexels-api swift
Last synced: about 1 year ago
JSON representation
Pexels API client library for the Swift programming language.
- Host: GitHub
- URL: https://github.com/lukepistrol/pexels-swift
- Owner: lukepistrol
- License: mit
- Created: 2022-05-12T21:59:02.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-27T06:15:32.000Z (about 2 years ago)
- Last Synced: 2025-04-25T01:53:38.061Z (about 1 year ago)
- Topics: ios, macos, pexels, pexels-api, swift
- Language: Swift
- Homepage:
- Size: 2.37 MB
- Stars: 13
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Pexels-Swift
[Pexels.com API](https://www.pexels.com/api) client library for the Swift programming language.

## Overview
This Swift Package is a wrapper for [Pexels API](https://www.pexels.com/api) to get access to the entire photo library of `Pexels` within your Swift app.
> It is mandatory to get an [API Key](https://www.pexels.com/api).
## Installation (SPM)
```swift
dependencies: [
.package(url: "https://github.com/lukepistrol/Pexels-Swift.git", from: "0.1.0")
],
```
## Documentation
See the full documentation [here](https://lukepistrol.github.io/Pexels-Swift/documentation/pexelsswift/) or build it locally using `โงโโD` in Xcode once you added `Pexels-Swift` to your project.
## Usage
```swift
import PexelsSwift
// access the singleton instance
let pexels = PexelsSwift.shared
// set your API key
pexels.setup(apiKey: "YOUR_API_KEY", logLevel: .debug)
// fetch images metadata using async/await
let result = await pexels.getCuratedPhotos()
switch result {
case .failure(let error):
print(error.description)
case .success(let (data, paging, response)):
// access photos
// data -> [PSPhoto]
// paging -> PSPagingInfo
// response -> HTTPURLResponse
}
// fetch images metadata using completion handlers
pexels.getCuratedPhotos() { result in
switch result {
case .failure(let error):
print(error.description)
case .success(let (data, paging, response)):
// access photos
// data -> [PSPhoto]
// paging -> PSPagingInfo
// response -> HTTPURLResponse
}
}
```
## Demo Project
I've built a simple iOS app - [PexelsBrowser](https://github.com/lukepistrol/PexelsBrowser) - using this library and SwiftUI.
