Swift SDK
Use Flipswitch with Swift via OpenFeature OFREP
Flipswitch works with Swift applications through the OpenFeature SDK and its native OFREP provider — no custom Flipswitch package needed.
GitHub: open-feature/swift-sdk · open-feature/ofrep-swift-client-provider
This integration uses the OpenFeature Remote Evaluation Protocol (OFREP), which evaluates flags via polling. Real-time SSE streaming is available in official Flipswitch SDKs.
Requirements
- Swift 5.9+
- iOS 15+ / macOS 13+
Installation
Add via Swift Package Manager:
https://github.com/open-feature/ofrep-swift-client-provider.gitQuick Start
import OpenFeature
import OFREPProvider
let provider = OFREPProvider(
baseURL: URL(string: "https://api.flipswitch.io")!,
headers: ["X-API-Key": "YOUR_API_KEY"]
)
OpenFeatureAPI.shared.setProvider(provider: provider)
let client = OpenFeatureAPI.shared.getClient()
let darkMode = client.getBooleanValue(key: "dark-mode", defaultValue: false)Evaluation Context
Pass user attributes for targeting:
let context = MutableContext(
targetingKey: "user-123",
structure: MutableStructure(attributes: [
"email": .string("user@example.com"),
"plan": .string("premium"),
"country": .string("SE")
])
)
let showFeature = client.getBooleanValue(key: "new-feature", defaultValue: false, context: context)Detailed Evaluation
Get full evaluation details including variant and reason:
let details = client.getBooleanDetails(key: "feature-flag", defaultValue: false, context: context)
print("Value: \(details.value)")
print("Variant: \(details.variant ?? "none")")
print("Reason: \(details.reason ?? "none")")SwiftUI Integration
import SwiftUI
import OpenFeature
struct FeatureView: View {
@State private var isEnabled = false
var body: some View {
VStack {
if isEnabled {
Text("New feature is live!")
} else {
Text("Coming soon")
}
}
.onAppear {
let client = OpenFeatureAPI.shared.getClient()
isEnabled = client.getBooleanValue(key: "new-feature", defaultValue: false)
}
}
}UIKit Integration
import UIKit
import OpenFeature
class FeatureViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let client = OpenFeatureAPI.shared.getClient()
let showBanner = client.getBooleanValue(key: "promo-banner", defaultValue: false)
if showBanner {
showPromoBanner()
}
}
}Direct OFREP API
You can also call the OFREP endpoints directly via HTTP — see the OFREP protocol reference for details.