# iOS quickstart (Swift)
Source: https://sovaria.in/docs/mobile-swift

Add Sovaria to a Swift app: install with SwiftPM, connect, sign in, read data, and keep the session in the Keychain.

> **Warning:** **Release pending:** the Swift package is not on a public SwiftPM URL yet, so the install step below won't resolve until it is. Ask for early access on [the early-access page](/early-access) and we'll share the package with your team. Every type and method: [Swift SDK](https://sovaria.in/docs/swift-reference).

1. **Install** — Add the package in Xcode (File › Add Packages) or in Package.swift.
```swift
.package(url: "https://github.com/sovaria/sovaria-swift.git", from: "1.0.0")
```
2. **Register your app** — Console › Authentication › Mobile › **Apps**: add the iOS bundle id + team id and a redirect URI such as `com.example.app://auth-callback`.
3. **Connect**
```swift
import Sovaria

let sovaria = try await Sovaria.initialize(
    url: "https://<ref>.sovarias.in",          // Project settings › API
    anonKey: "svr_anon_…",                     // public; safe to ship in the app
    storage: KeychainStore(),                  // Keychain (see below)
    device: SovariaDevice(id: deviceId, platform: "ios", name: deviceName)
)
```
4. **Keep the session in the Keychain**
```swift
final class KeychainStore: SessionStorage {
    func read(_ key: String) async -> String? { /* Keychain read */ }
    func write(_ key: String, _ value: String) async { /* Keychain write */ }
    func delete(_ key: String) async { /* Keychain delete */ }
}
```
5. **Sign in and use data**
```swift
try await sovaria.auth.signInWithPassword(email: email, password: password)

let todos = try await sovaria.db.select("todos", where: ["done": false], orderBy: "created_at", limit: 20)
try await sovaria.files.upload("avatars", "\(sovaria.auth.currentSession!.userId!)/me.png", data, contentType: "image/png")

let channel = sovaria.realtime.channel("room:42") { message in print(message) }
try await channel.send(["text": "hi"])
```

> **Tip:** Iterate `sovaria.auth.changes` to switch between your signed-in and signed-out screens; the first event is `.initialSession` with the current session. Tokens refresh on their own.

## Deep links, push and attestation

Swift:
```swift
// Provider sign-in, magic links, email confirmations (PKCE-bound when the link opens the app)
.onOpenURL { url in Task { if let r = try await sovaria.auth.handleDeepLink(url), r.type == "recovery" { showNewPassword(r.token!) } } }

// Push: the APNs token from didRegisterForRemoteNotificationsWithDeviceToken
try await sovaria.push.registerAPNs(deviceToken: token)

// App attestation: App Attest on devices, a debug token on the simulator
let sovaria = Sovaria(url: url, anonKey: anonKey,
                      attestation: isSimulator ? DebugAttestationProvider(debugToken: token) : AppAttestProvider(appId: "com.acme.app", storage: KeychainStore()))
```

## Every operation

`sovaria.api.<module>.<method>(…)` exposes every Sovaria operation, generated from the same description as the JavaScript, Python, Dart and Kotlin SDKs (a golden-request test checks they send identical requests); `sovaria.api.call(method, path, …)` reaches any path. Wrappers: `auth` (with `handleDeepLink`), `db`, `collections`, `files`, `functions`, `realtime`, `push`, `crashes`, `simulate`, and `enableOffline()`.

Realtime channels report `connecting`, `live`, `reconnecting` and `closed`, as in the other SDKs. A function that answers plain text comes back as a `String`.

Errors are `SovariaError` with `status`, `code` (`PLAN_LIMIT_REACHED`, `PKCE_REQUIRED`, `APP_ATTESTATION_REQUIRED`…) and a plain `message`. Foundation only — no third-party dependencies; iOS 15+/macOS 12+.
