Bullet Train iOS Client
BulletTrainClient is an iOS Client written in Swift for Bullet-Train. Ship features with confidence using feature flags and remote config.
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate Alamofire into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'BulletTrainClient', '~> 1.0'
Usage
Sign Up
Sign up at Bullet Train and create a project. Take a note of the API key which you will need to configure your app.
Initialization
Within your application delegate (usually AppDelegate.swift) add:
import BulletTrainClient
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
BulletTrain.shared.apiKey = "<YOUR_API_KEY>"
// The rest of your launch method code
}
Now you are all set to retrieve feature flags from your project. For example to list and print all flags:
BulletTrain.shared.getFeatureFlags() { (result) in
switch result {
case .success(let flags):
for flag in flags {
let name = flag.feature.name
let value = flag.value
print(name, "=", value ?? "nil")
}
case .failure(let error):
print(error)
}
}
To retrieve a feature value by its name:
BulletTrain.shared.getFeatureValue(withID: "test_feature2", forIdentity: nil) { (result) in
switch result {
case .success(let value):
print(value ?? "nil")
case .failure(let error):
print(error)
}
}
These methods can also specify a particular identity to retrieve the values for a user registration. See Identities , using the forIdentity parameter.
To retrieve a trait for a particular identity (see Traits):
BulletTrain.shared.getTraits(forIdentity: "[email protected]") {(result) in
switch result {
case .success(let traits):
for trait in traits {
let name = trait.key
let value = trait.value
print(name, "=", value)
}
case .failure(let error):
print(error)
}
}