OpenFeature Provider for iOS SDK
Integrate your iOS applications with Harness FME using the iOS OpenFeature ProviderAn OpenFeature Provider wraps the Harness FME SDK, acting as a bridge between the OpenFeature SDK and the FME SDK. It translates OpenFeature function calls into operations handled by the FME SDK, which communicates with Harness services to evaluate flags and retrieve configuration updates., a standardized, vendor-agnostic feature flagging API. This provider implements the OpenFeature specification and bridges the OpenFeature SDK with the Harness FME iOS SDK.
This page walks you through installing, configuring, and using the iOS OpenFeature provider to evaluate feature flagsA feature flag is a conditional toggle in Harness FME that enables or disables specific functionality without deploying new code. It allows for controlled feature rollouts, A/B testing, and quick rollbacks if issues arise. in your iOS applications.
Prerequisites
Before you begin, ensure you have the following:
- A valid Harness FME SDK key for your project
- An iOS project (Xcode 14+)
- Access to your project's
Package.swiftfile or Xcode project to add the provider dependency
Version compatibility
| Component | Minimum Version |
|---|---|
| iOS | ≥ 14 |
@splitsoftware/split-openfeature-provider-swift | ≥ 1.0.0 |
| OpenFeature Swift SDK | ≥ 0.4.0 |
Install the provider and dependencies
Add the Harness FME OpenFeature provider dependency to your application's Xcode project using Swift Package Manager.
.package(url: "https://github.com/splitio/split-openfeature-provider-swift", from: "1.0.0")
Initialize the provider
The Harness FME OpenFeature provider requires an iOS application Context (for SDK initialization) and your Harness FME SDK Key.
import Split
import Combine
import OpenFeature
import SplitProvider
Task {
var providerCancellable: AnyCancellable?
let provider = SplitProvider(key: "API_KEY")
// Setup events observer
providerCancellable = OpenFeatureAPI.shared.observe().sink { [weak self] event in
switch event {
case .ready:
print("Split Provider is ready")
case .error(let message):
print("Split Provider error:", message)
default:
break
}
}
// Setup OpenFeature with initial context
let context = ImmutableContext(targetingKey: "user_key")
await OpenFeatureAPI.shared.setProviderAndWait(provider: provider, initialContext: context)
// Get a client and evaluate a flag
let client = OpenFeatureAPI.getClient()
let flagEvaluationResult = client.getBooleanValue("new-feature", false)
}
Construct an evaluation context
Provide an evaluation contextThe Evaluation Context holds contextual information used during flag evaluation. It can include static data (like application or host identifiers) and dynamic data (such as a client IP address), which can be passed explicitly or propagated automatically. Static and dynamic values can be merged for richer, more targeted evaluations. with a targeting keyA unique identifier used to target specific users or entities when evaluating feature flags. It helps determine which variation of a flag should be served based on predefined rules and conditions. to evaluate flags. The evaluation context passes targeting information such as user IDs, email addresses, or plan types for flag targeting.
For example:
let context = ImmutableContext(
targetingKey: "martin",
structure: ImmutableStructure(attributes: [
"email": Value.String(someValue),
"age": Value.Integer(30)
]))
OpenFeatureAPI.shared.setEvaluationContext(evaluationContext: context)
let client = OpenFeatureAPI.getClient()
let result = client.getBooleanDetails("premium-feature", false, context)
To set a targeting key during initialization:
let initialContext = ImmutableContext(targetingKey = "user-123")
OpenFeatureAPI.setProvider(provider, initialContext = initialContext)
To change a targeting key at runtime:
let newContext = ImmutableContext(targetingKey = "user-456")
OpenFeatureAPI.setEvaluationContext(newContext)
Observe provider events
The Harness FME OpenFeature provider emits eventsEvents allow your application to respond to changes in provider state or flag configuration, such as readiness changes, errors, or updates to flag values. when provider state changes (for example, when flags update, configuration changes, or errors) occur. You can observe these events to update your application's behavior in real time.
You can enable your application to:
- Refresh feature-dependent UI when flags change
- Gracefully handle degraded states (i.e., when the provider becomes stale)
- Log or alert on configuration or network issues
- Control initialization flows based on provider readiness
For example:
import Combine
let cancellable = OpenFeatureAPI.shared.observe().sink { event in
switch event {
case ProviderEvent.ready:
// Provider ready
case ProviderEvent.stale:
// Provider stale
case ProviderEvent.configurationChanges:
// Configuration changed
case ProviderEvent.contextChanged:
// Context updated
case ProviderEvent.error(let errorCode, let message):
// Handle error
default:
break
}
}
For more information, go to the Harness FME iOS OpenFeature Provider GitHub repository.