Docs

iOS quickstart (Swift)

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

Updated Oct 26, 2026
  1. Install

    Add the package in Xcode (File › Add Packages) or in Package.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

    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

    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

    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"])
// 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+.