UNClient

public class UNClient

The UNClient is the point of access to every Unsplash request.

  • Returns a shared singleton object.

    Declaration

    Swift

    public static let shared = UNClient()
  • Boolean value indicating whether the credentials have been set.

    Declaration

    Swift

    public  var hasCredentials : Bool
  • Sets the credentials for the Unsplash client. This function should only be called once.

    Declaration

    Swift

    public func setAppID(_ appID: String, secret: String)

    Parameters

    appID

    The application ID Unsplash provided you with.

    secret

    The secret Unsplash provided you with.

  • Get a single page from the list of all photos.

    Declaration

    Swift

    public func listPhotos(page: Int,
                           photosPerPage: Int = 10,
                           sortingBy sort: UNSort,
                           completion: @escaping UNPhotoQueryClosure)

    Parameters

    page

    Page number to retrieve.

    photosPerPage

    Number of items per page.

    sort

    How to sort the photos.

    completion

    The completion handler that will be called with the results (Executed on the main thread).

  • Fetches the image corresponding to the photo on the specified size.

    Declaration

    Swift

    public func fetchImage(from photo: UNPhoto,
                           inSize size: UNPhotoImageSize,
                           completion: @escaping (UNPhoto, UNPhotoImageSize, UIImage?, UNError?) -> Void)

    Parameters

    photo

    The photo to download the image from.

    size

    One of the available sizes for the image to be downloaded.

    completion

    The completion closure to handle the result. It will be called on the main thread.

  • Fetches the image corresponding to the photo on the specified size.

    Declaration

    Swift

    public func fetchDataImage(from photo: UNPhoto,
                               inSize size: UNPhotoImageSize,
                               completion: @escaping UNFetchDataImageClosure)

    Parameters

    photo

    The photo to download the image from.

    size

    One of the available sizes for the image to be downloaded.

    completion

    The completion closure to handle the result. The image will be passed as a Data. It will be called on the main thread.

  • The image will be fetched and passed back to the specified requester. This function is exclusive since the requester will only have one active request at a time. Any new request by the same object will cancel the previous one. This is useful for table views or collection views where the cell may be reuse for another photo before the previous requested image is dowloaded.

    Declaration

    Swift

    public func fetchDataImageExclusively(from photo: UNPhoto,
                                          inSize size: UNPhotoImageSize,
                                          for requester: UNImageRequester)

    Parameters

    photo

    The photo that corresponds to the desired image.

    size

    The size of the image to be downloaded.

    requester

    The object that is interested in the image and the one who will be called back.