This package provides a DevCycle provider implementation for the OpenFeature iOS SDK feature flagging SDK. It allows you to use DevCycle as the feature flag management system behind the standardized OpenFeature API.
The DevCycle OpenFeature Provider requires iOS 14.0+ / tvOS 14.0+ / watchOS 7.0+ / macOS 11.0+
Add the dependency to your Package.swift
file:
.package(url: "https://github.com/DevCycleHQ/ios-openfeature-provider.git", from: "1.0.0")
Then add DevCycleOpenFeatureProvider
to your target's dependencies:
.target(
name: "YourTarget",
dependencies: [
.product(name: "DevCycleOpenFeatureProvider", package: "ios-openfeature-provider")
]
)
Note that this package automatically includes the DevCycle SDK as a dependency.
import OpenFeature
import DevCycle
import DevCycleOpenFeatureProvider
// Configure DevCycle options if needed
let options = DevCycleOptions.builder()
.logLevel(.debug)
.build()
// Configure the DevCycle provider
let provider = DevCycleProvider(sdkKey: "<DEVCYCLE_MOBILE_SDK_KEY>", options: options)
// Set up the evaluation context
let evaluationContext = MutableContext(
targetingKey: "user-123",
structure: MutableStructure(attributes: [
"email": .string("user@example.com"),
"name": .string("Test User"),
"customData": .structure(["customkey": .string("customValue")])
])
)
// Initialize OpenFeature with the DevCycle provider
Task {
// Set the provider with initial context
await OpenFeatureAPI.shared.setProviderAndWait(
provider: provider, initialContext: evaluationContext)
// Get a client
let client = OpenFeatureAPI.shared.getClient()
// Evaluate flags
let boolValue = client.getBooleanValue(key: "my-boolean-flag", defaultValue: false)
let stringValue = client.getStringValue(key: "my-string-flag", defaultValue: "default")
print("Bool flag value: \(boolValue)")
print("String flag value: \(stringValue)")
// Update context later if needed
let newContext = MutableContext(
targetingKey: "user-123",
structure: MutableStructure(attributes: [
"country": .string("CA")
])
)
await OpenFeatureAPI.shared.setEvaluationContextAndWait(evaluationContext: newContext)
}
An example iOS application demonstrating how to use the DevCycle OpenFeature Provider can be found in the Examples directory. This example shows how to:
- Initialize the DevCycle provider
- Set up an evaluation context
- Evaluate different types of feature flags
- Handle flag changes
To build and test the provider:
swift build
swift test
During development, you might want to test this provider with a local copy of the DevCycle SDK. To do this, you can temporarily modify the Package.swift
file to use a local path reference:
// In Package.swift, replace:
.package(
name: "DevCycle",
url: "https://github.com/DevCycleHQ/ios-client-sdk.git",
.upToNextMajor(from: "1.18.0")
)
// With:
.package(
name: "DevCycle",
path: "../ios-client-sdk" // Adjust the path to your local DevCycle SDK repo
)
This setup allows for easier development and testing:
- Changes to the main DevCycle SDK are immediately reflected in the provider
- You can test changes to both packages together without publishing
- Make sure to revert this change before committing
This package depends on: