UnsplashFramework

The idea behind this project is to make an easy-to-use, well tested and well documented client framework for Unsplash.

Currently in early development stage ?

? Plan

  • [x] List photos
  • [x] Search photos
  • [x] Search collections
  • [x] Search user
  • [ ] List collections
  • [ ] Users

Requirement

  • iOS 14.5+
  • XCode 13.0+

⬇️ Installation

CocoaPods

Add the following to your Podfile:

pod 'UnsplashFramework', '~> 0.1'
Ruby

Carthage

Add the following to your Cartfile:

github "camiletti/UnsplashFramework" ~> 0.1
Ogdl

? Use

import UnsplashFramework
Swift

Credentials

Before doing any request, the Unsplash client credentials should be set. If you haven't registered yet, you can do so here.

let credentials = UNCredentials(appID: "Your_AppID", secret: "Your_Secret"
let client = UNClient(with: credentials)
Swift

Listing photos

client.listPhotos(page: 1,
                  photosPerPage: 10,
                  sortingBy: .popular)
    { result in
        switch result {
        case .success(let photos):
            photos.forEach({ (photo) in
                print("Photo with ID: \(photo.id) from user: \(photo.user.username) main color: \(photo.hexColor)")
            })

        case .failure(let error):
            print("Error: \(error.reason)")
    }
}
Swift

Searching photos

client.searchPhotos(query: "Forest",
                    page: 1,
                    photosPerPage: 10,
                    collections: nil,
                    orientation: .landscape)
    { result in
        switch result {
        case .success(let searchResult):
        searchResult.photos.forEach { (photo) in
            print("Photo with ID: \(photo.id) from user: \(photo.user.username) main color: \(photo.hexColor)")
        }
        
        case .failure(let error):
            print("Error: \(error.reason)")
        }
    }
Swift

GitHub

https://github.com/camiletti/UnsplashFramework