Swiftpack.co - lukepistrol/Pexels-Swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by lukepistrol.
lukepistrol/Pexels-Swift 0.9.3
Pexels API client library for the Swift programming language.
โญ๏ธ 2
๐Ÿ•“ 5 days ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/lukepistrol/Pexels-Swift.git", from: "0.9.3")

GitHub Workflow Status GitHub Twitter: @lukeeep_

Pexels-Swift

Pexels.com API client library for the Swift programming language.

Banner

Overview

This Swift Package is a wrapper for Pexels API to get access to the entire photo library of Pexels within your Swift app.

It is mandatory to get an API Key.

Installation (SPM)

dependencies: [
  .package(url: "https://github.com/lukepistrol/Pexels-Swift.git", from: "0.1.0")
],

Documentation

See the full documentation here or build it locally using โ‡งโŒƒโŒ˜D in Xcode once you added Pexels-Swift to your project.

Usage

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 - using this library and SwiftUI.

Buy Me A Coffee

GitHub

link
Stars: 2
Last commit: 4 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

0.9.3
5 days ago

0.9.3

  • added support for tvOS and watchOS

0.9.2

  • fixed per_page coding key typo. Thanks to @SugiKent

0.9.1

  • added rate limit tracking. See Rate Limits for more information.

0.9.0

Breaking Changes:

  • added HTTPURLResponse to results tuple:
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
}

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics