Examples

SwiftUI

A complete SwiftUI app that owns an AirStrings instance, renders plain and ICU strings, and switches language at runtime.

A minimal but complete SwiftUI app using the AirStrings iOS SDK. One instance owned at the root, injected through the environment, read from any view. For every configuration field in detail, see the iOS SDK reference.

Strings used in this example

KeyFormatValue
home.welcome_titletextWelcome!
home.items_counticu{count, plural, one {# item} other {# items}}

Add the package

In Xcode, choose File > Add Package Dependencies and enter the repository URL, or add it to your Package.swift:

dependencies: [
    .package(url: "https://github.com/symbionix-sl/airstrings-sdk-ios.git", from: "1.1.1")
]

The whole app

The @main App struct owns the instance with @State and injects it with .environment(\.airStrings, airStrings). Views read it back via @Environment(\.airStrings). The subscript returns the raw value; string(_:args:) formats ICU patterns. setLocale(_:) switches language at runtime. The view re-renders automatically because AirStrings is @Observable.

import SwiftUI
import AirStrings

@main
struct DemoApp: App {
    @State private var airStrings = AirStrings(configuration: .init(
        organizationId: "org_...",
        projectId: "proj_...",
        environmentId: "env_...",
        publicKeys: ["pk_..."]
    ))

    var body: some Scene {
        WindowGroup {
            HomeView()
                .environment(\.airStrings, airStrings)
        }
    }
}

struct HomeView: View {
    @Environment(\.airStrings) private var strings
    @State private var selectedLocale = "en"

    private let locales = ["en", "es", "fr"]

    var body: some View {
        NavigationStack {
            Form {
                Section {
                    Text(strings["home.welcome_title"])
                    Text(strings.string("home.items_count", args: ["count": 3]))
                }
                Section {
                    Picker("Language", selection: $selectedLocale) {
                        ForEach(locales, id: \.self) { locale in
                            Text(locale)
                        }
                    }
                }
            }
            .navigationTitle(strings["home.welcome_title"])
            .onChange(of: selectedLocale) {
                Task { await strings.setLocale(selectedLocale) }
            }
        }
    }
}

Run it

On first launch the SDK loads any cached bundle immediately, then fetches the latest signed bundle in the background. The view updates when it lands. Picking a different language calls setLocale(_:), which loads the cached bundle for that locale and fetches the latest. If no bundle has ever loaded, keys are shown as fallback.

On this page