Skip to content

Swift Platforms

PlatformMinimum Version
macOS13.0+
iOS16.0+
tvOS16.0+
watchOS9.0+
import SwiftUI
import FlagsGG
@main
struct MyApp: App {
let flags: Flags
init() {
flags = try! Flags.builder()
.withAuth(Auth(
projectId: "your-project-id",
agentId: "your-agent-id",
environmentId: "your-environment-id"
))
.build()
}
var body: some Scene {
WindowGroup {
ContentView(flags: flags)
}
}
}
struct ContentView: View {
let flags: Flags
@State private var showBeta = false
var body: some View {
VStack {
if showBeta {
Text("Beta feature!")
}
}
.task {
showBeta = await flags.is("beta-ui").enabled()
}
}
}

For server-side Swift (e.g., Vapor), initialize the client once and share it across request handlers:

import Vapor
import FlagsGG
func configure(_ app: Application) throws {
let flags = try Flags.builder()
.withAuth(Auth(
projectId: "your-project-id",
agentId: "your-agent-id",
environmentId: "your-environment-id"
))
.build()
app.storage[FlagsKey.self] = flags
}

The Swift SDK maintains API compatibility with the Rust SDK:

RustSwift
client.is("name").enabled().awaitawait client.is("name").enabled()
client.list().await?try await client.list()
client.get_multiple(&[...]).awaitawait client.getMultiple([...])
client.all_enabled(&[...]).awaitawait client.allEnabled([...])
client.any_enabled(&[...]).awaitawait client.anyEnabled([...])