# iOS quickstart

> The native Size guide button (SwiftUI and UIKit), the shopper's recommended size, and the try-on window in a sheet.

Source: https://docs.tryyoursize.com/quickstarts/ios/

> **For your developer**
>
> **What it does:** Adds a native 'Size guide' button next to the size picker in our iOS app. Connected shoppers see 'Your size: M'; a tap opens the TryYourSize window in a sheet. The app receives sizes only.
>
> **Time needed:** About a day, including registering the app.
>
> **What to send them:** The test publishable key (pk_test_…) and our app's bundle ID to register as ios-app://<bundle id>.

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

> **Caution: Test mode only for apps, for now**
>
> App origins (`ios-app://…`) are accepted in test mode. Live mode for apps needs app verification (associated domains), which is coming soon. Public distribution of the Swift package and pod is also coming soon: during the pilot we share the package with you.

## 1. Install

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

## 2. Register your app

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`.

## 3. Use it

```swift

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.

## 4. Appearance

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.

```swift
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
```

## 5. Events and errors

- **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.

## Sign-in

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.
