Skip to content

iOS quickstart

iOS 16+, Swift 5.9+, SwiftUI and UIKit.

  • Swift Package Manager: File → Add Package Dependencies → the TryYourSize package, product TryYourSize.
  • CocoaPods: pod 'TryYourSize' (with the :path or source we share).

In Studio, add ios-app://<your bundle id> (lower case, for example ios-app://com.brand.shop) to the allowed sites of your store for test mode. Until it is registered, the button reports app_not_allowed.

import TryYourSize
let tys = try TryYourSize(publishableKey: "pk_test_…") // a secret key throws: keep sk_ on your server
// SwiftUI, where your "Size guide" link was:
HStack {
Text("Size")
Spacer()
SizeGuide(client: tys, product: "SKU-123") { rec in
// On show and on every change. Preselect, but never over the shopper's own choice.
if rec.status == .ready, let size = rec.size, !touched { selectedSize = size }
}
}
// UIKit
let guide = SizeGuideButton(client: tys, product: "SKU-123", variant: .button)
guide.onRecommendation = { rec in /* … */ }
// Without a button
let rec = try await tys.recommendation(for: "SKU-123")
tys.present(product: "SKU-123") // open the window yourself
tys.on { event in if case let .size(s) = event { select(s.size) } } // "Use this size" in the window

Button states: “Size guide” (signed out) → “Calculating your size…” → “Your size: M” (with the connected dot), or “Size guide · connected”. Labels follow locale (en, es, fr, de, it); label: sets your own words.

Recommendation: status (.ready, .computing, .noSize, .signedOut, .unavailable), size in your labels, studioSize, wearableSizes. The web SDK’s "none" is .noSize in Swift. A recommendation never starts a simulation.

By default (.inherit) the button takes your SwiftUI font and text colour, and the window takes your app’s text and background colours, dark mode included.

let config = TryYourSize.Configuration(appearance: Appearance(
colorPrimary: TYSColor(UIColor.systemIndigo), fontFamily: "Inter, -apple-system", borderRadius: 12,
fonts: [URL(string: "https://fonts.googleapis.com/css2?family=Inter:wght@400;600")!]))
let tys = try TryYourSize(publishableKey: "pk_test_…", configuration: config)
tys.appearance.colorPrimary = TYSColor(hex: "#111111") // live: an open window restyles at once
  • Events (tys.on): .ready, .open, .close, .size(SizeSelection), .loadError(TryYourSizeError).
  • Error codes (TryYourSizeError.code): secret_key_in_app, invalid_key, invalid_app_identifier, invalid_option, window_unreachable, app_not_allowed, sign_in_cancelled, sign_in_unavailable.
  • Swiping the sheet down asks the window first: with unsaved measurements, the shopper confirms.

Shoppers sign in inside the window (email and a 6-digit code), once per app. Sign-in through the system browser with passkeys, sharing the shopper’s tryyoursize.com session, is coming soon.

Was this page helpful?