Documentation Index
Fetch the complete documentation index at: https://docs.grantiva.io/llms.txt
Use this file to discover all available pages before exploring further.
Feature flags let you control feature rollout from the Grantiva dashboard without app updates. Access them via grantiva.flags.
Get all flags
let flags = try await grantiva.flags.getFlags()
if flags["dark_mode"]?.boolValue == true {
enableDarkMode()
}
Flags are cached in memory for 5 minutes by default. See Cache control to configure the TTL.
Typed accessors
// Boolean (default: false)
let enabled = try await grantiva.flags.boolValue(for: "dark_mode", default: false)
// String (default: "")
let theme = try await grantiva.flags.stringValue(for: "theme", default: "light")
// Integer (default: 0)
let limit = try await grantiva.flags.intValue(for: "upload_limit", default: 10)
// Double (default: 0.0)
let threshold = try await grantiva.flags.doubleValue(for: "risk_threshold", default: 0.5)
Default values are returned when the flag doesn’t exist or can’t be parsed to the requested type.
Get a single flag
if let value = try await grantiva.flags.value(for: "feature_x") {
print(value.rawValue) // Raw string from server
print(value.valueType) // FlagValueType: boolean, integer, double, string, json
print(value.boolValue) // Bool?
print(value.intValue) // Int?
print(value.stringValue) // String (always succeeds)
print(value.jsonValue) // Any? (parsed JSON)
}
Environments
Flags can be scoped to different environments:
grantiva.flags.environment = .staging // .development, .staging, .production
let flags = try await grantiva.flags.getFlags(forceRefresh: true)
Default is .production.
Cache control
Flags are cached for 5 minutes by default. Adjust the TTL at any point after initialization:
// 30-second TTL — fast propagation for kill-switches
grantiva.flags.cacheTTL = 30
// Disable caching entirely — always fetch fresh values
grantiva.flags.cacheTTL = 0
// Force refresh on next fetch
await grantiva.flags.refresh()
// Clear all cached flag data
await grantiva.flags.clearCache()
The cache is automatically cleared when user identity changes via grantiva.identify().
Tier limits
| Tier | Max flags |
|---|
| Free | 10 |
| Pro | 50/app |
| Business | 200/app |
| Enterprise | Unlimited |