Optidash Blog

Introducing Our Official SDK for Swift

Introducing the official Swift SDK for Optidash: Elevate your iOS and MacOS apps with precision-driven image optimization and processing API access.

Have you ever wished to integrate precision-driven image optimization and processing API, like Optidash, directly into your iOS and MacOS applications? If so, we have great news for you – introducing the official Swift SDK for the Optidash API.

Quick example

Swift SDK, developed by our friends at Inspace Labs, is available for iOS and MacOS developers, and covers the entire Optidash API. You can find the latest source code on our GitHub.

Let’s have a look at an example request using Image Upload on iOS:

let fileUrl = Bundle.main.url(forResource: "sample", withExtension: "jpg")!

let resizeParams: [String : Any] = [
    "mode": "fit",
    "gravity": "face",
    "width": 640,
    "height": 480
]

let opti = OptidashClient(key: "YOUR-API-KEY")

do {
    try opti.upload(fileUrl: fileUrl)
            .resize(resizeParams)
            .toImageData() { [weak self] (result) in
                switch (result) {
                case .success(let data):
                    DispatchQueue.main.async {
                        let image = UIImage(data: data)
                        self?.outputImageView.image = image
                    }
                case .failure(let error):
                    DispatchQueue.main.async {
                        self?.outputLabel.text = "Error: \(error)"
                    }
                }
            }
} catch let error {
    outputLabel.text = "Error: \(error)"
}

Installation with Carthage

Carthage is a decentralized dependency manager designed to streamline the process of integrating frameworks into your Cocoa application. To install Carthage using Homebrew, simply execute the following command:

$ brew update
$ brew install carthage

To integrate Optidash into your Xcode project using Carthage, add the following line to your Cartfile:

github "optidash-ai/optidash-swift"

Installation with CocoaPods

To integrate Optidash into your Xcode project using CocoaPods, add the following line to your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
pod 'Optidash', '~> 1.0.0'

Wrapping Up

Should you have any questions about the Swift SDK or if you have any requests for other integrations, please don’t hesitate to contact us anytime.