Swift SDK

Last updated · Changelog · OpenAPI spec · Markdown

Our official Swift SDK provides native iOS and macOS integration with modern Swift concurrency and SwiftUI support.

Installation

Swift Package Manager:

.package(url: "https://github.com/shopsavvy/sdk-swift.git", from: "1.3.0")

Quick Start

import ShopSavvy

// Create a new client
let client = ShopSavvyClient(apiKey: "ss_live_your_api_key_here")

// Get product details
do {
    let product = try await client.getProductDetails("012345678901")
    print("Product: \(product.data.name)")

    // Get current offers
    let offers = try await client.getCurrentOffers("012345678901")
    for offer in offers.data {
        print("\(offer.retailer): $\(offer.price, specifier: "%.2f")")
    }

    // Get price history
    let history = try await client.getPriceHistory(
        "012345678901",
        startDate: "2024-01-01",
        endDate: "2024-01-31"
    )

} catch {
    print("Error: \(error)")
}

SwiftUI Integration

struct ProductView: View {
    @State private var product: Product?
    @State private var offers: [Offer] = []

    let barcode: String
    let client = ShopSavvyClient(apiKey: "your_api_key")

    var body: some View {
        VStack {
            if let product = product {
                Text(product.name)
                    .font(.title)

                LazyVStack {
                    ForEach(offers, id: \.id) { offer in
                        HStack {
                            Text(offer.retailer)
                            Spacer()
                            Text("$\(offer.price, specifier: "%.2f")")
                        }
                    }
                }
            }
        }
        .task {
            await loadProduct()
        }
    }

    private func loadProduct() async {
        do {
            let productResponse = try await client.getProductDetails(barcode)
            let offersResponse = try await client.getCurrentOffers(barcode)

            await MainActor.run {
                self.product = productResponse.data
                self.offers = offersResponse.data
            }
        } catch {
            print("Error loading product: \(error)")
        }
    }
}

Features

  • Modern Swift concurrency (async/await)
  • SwiftUI and UIKit support
  • Codable models for type safety
  • iOS 15+ and macOS 12+ support
  • Built-in error handling
  • Network layer with URLSession
Was this page helpful?