Swift Configuration
Client Builder
Section titled “Client Builder”let client = try Flags.builder() .withAuth(Auth( projectId: "your-project-id", agentId: "your-agent-id", environmentId: "your-environment-id" )) .withBaseURL("https://custom-api.flags.gg") .withMaxRetries(5) .withErrorCallback { error in print("Flag error: \(error)") } .build()Builder Methods
Section titled “Builder Methods”| Method | Default | Description |
|---|---|---|
withAuth(Auth) |
— | Required. Authentication credentials |
withBaseURL(String) |
https://api.flags.gg |
Custom API endpoint |
withMaxRetries(Int) |
3 |
Max retry attempts |
withErrorCallback((FlagsError) -> Void) |
— | Error callback handler |
withTargetingKey(String?) |
Install id | Stable user id for percentage rollouts |
withMemoryCache() |
Memory | Use in-memory cache |
withSQLiteCache(path:) |
flags_cache.db |
Use a SQLite cache, so the last values survive a restart (Apple platforms) |
withCache(any Cache) |
— | Use your own cache |
withContext([String: [String]]) |
— | User attributes for targeting rules. A [String: String] overload is also available |
Rollouts and Targeting Rules
Section titled “Rollouts and Targeting Rules”let client = try FlagsClient.builder() .withAuth(auth) .withTargetingKey(user?.id) // nil falls back to the install id .withContext(["email": [user.email], "plan": [user.plan], "groups": user.groups]) .build()
// later, e.g. after login or an upgrade; re-fetches flagsawait client.setTargetingKey(user.id)await client.setContext(["plan": ["pro"]])isEnabled already accounts for both. See Rollouts & Targeting Rules.
Error Types
Section titled “Error Types”| Error | Description |
|---|---|
httpError |
Network or HTTP errors |
cacheError |
Cache operation errors |
authError |
Authentication errors |
apiError |
API response errors |
builderError |
Configuration errors |
Without Authentication
Section titled “Without Authentication”You can use the client with only local flags (environment variables):
let client = try Flags.builder().build()
// Only checks FLAGS_* environment variableslet enabled = await client.is("my-feature").enabled()Actor Model
Section titled “Actor Model”The client uses Swift actors for thread safety. All operations are safe for concurrent access without explicit locking.
