Swiftpack.co - ArnavMotwani/UnsplashSwiftUI as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ArnavMotwani.
ArnavMotwani/UnsplashSwiftUI v2.1.0
This SwiftUI package makes using the Unsplash API in an app simple and easy.
⭐️ 8
🕓 2 years ago
iOS macOS
.package(url: "https://github.com/ArnavMotwani/UnsplashSwiftUI.git", from: "v2.1.0")

UnsplashSwiftUI

This SwiftUI package makes using the Unsplash API in an app simple and easy.

Call the view and apply modifiers to it like you would with any other view. The package will fetch the image metadata from the API and it will load the remote image asynchronously. The view also has a text in the bottom left corner crediting the photographer as well as hotlinking to the image on Unsplash (A requirement while using the API).

Requirements:

The package is only compatible with iOS 15 and iPadOS 15 for now. Previous releases of this package support older OS versions however this release uses the new concurrency features as well as the new AsyncImage View

The package requires a Access Key (Client ID) for the Unsplash API. You can get one from the Unsplash Developers page. You'll need to register your app there and you will be Rate Limited (limited number of API requests per hour) until you apply for a high-volume application (refer to the Unsplash Developers page for more details)

Disclamer: I have not attempted applying for a high-volume application using this library as of yet. I believe that I have met all the requirements of the API and you should have no problem with it however I am not completely sure.

Installation:

In Xcode go to File -> Add Packages and paste in the repo's url: https://github.com/ArnavMotwani/UnsplashSwiftUI.git then either select a version or the main branch (I will update the main branch more frequently with minor changes, while the version number will only increase with significant changes)

Usage:

Import the package into the file with import UnsplashSwiftUI then call the UnsplashRandom view wherever you want.

Examples:

import SwiftUI
import UnsplashSwiftUI

struct UnsplashRandomTest: View {
    var body: some View {
        UnsplashRandom(clientId: "YOUR_ACCESS_KEY")
    }
}

struct UnsplashRandomTest_Previews: PreviewProvider {
    static var previews: some View {
        UnsplashRandomTest()
    }
}
import SwiftUI
import UnsplashSwiftUI

struct UnsplashRandomTest: View {
    var body: some View {
        UnsplashRandom(clientId: "YOUR_ACCESS_KEY")
        .padding(25)
    }
}

struct UnsplashRandomTest_Previews: PreviewProvider {
    static var previews: some View {
        UnsplashRandomTest()
    }
}
import SwiftUI
import UnsplashSwiftUI

struct UnsplashRandomTest: View {
    var body: some View {
        UnsplashRandom(clientId: "YOUR_ACCESS_KEY")
        .clipShape(RoundedRectangle(cornerRadius: 10))
    }
}

struct UnsplashRandomTest_Previews: PreviewProvider {
    static var previews: some View {
        UnsplashRandomTest()
    }
}

Customizations:

Parameter Optional? Type Description Default
clientId No String Client ID from the Unsplash Developer page -
orientation Yes Orientations Filter by photo orientation. (Valid values: .landscape, .portrait, .squarish, .none) -
query Yes String Limit selection to photos matching a search term. -
textColor Yes Color Color of the text hotlinked to image on Unsplash Color.white
textBackgroundColor Yes Color Color of text background (opacity set to 0.2 automatically) Color.black
aspectRatio Yes ContentMode Choose whether the image fits or fills the container ContentMode.fit

Examples:

orientation

    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", orientation: .landscape)
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", orientation: .portrait)
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", orientation: .squarish)

query

    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", query: "trees")
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", query: "landscapes")
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", query: "space")

textColor

    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", textColor: .black)
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", textColor: .blue)
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", textColor: .primary)

textBackgroundColor

    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", textBackgroundColor: .white)
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", textBackgroundColor: .blue)
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", textBackgroundColor: .primary)

aspectRatio

    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", aspectRatio: .fit)
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", aspectRatio: .fill)

GitHub

link
Stars: 8
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v2.1.0
2 years ago

This version allows you to call the UnsplashRandom view multiple times.

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