Getting started with iOS SDK

3 minute read

This section describes how to set up and install the iOS SDK and how to deploy a feature flag.

Step 1 - Setting up the iOS SDK

To setup iOS SDK, follow these steps:

  1. Create a CloudBees Feature Management account. See Signup Page to create an account.

  2. Get your environment key.

    • Get the key from App Settings > Environment > Key.

Step 2 - Installing the iOS SDK

For instructions on initializing the iOS package to your application., select your installation method:

CocoaPods

To install the iOS package, follow these steps:

  1. In the podfile, add the following:

    pod 'ROX'
  2. To install the Cocoapods dependencies, run the following command in the terminal:

    pod install

Carthage (SDK5)

SDK5 only.

To install the iOS package, follow these steps:

  1. In the cartfile, add the following:

    github "rollout/rox-spm"
  2. To install the Carthage dependencies, run the following command in the terminal:

    carthage update --use-xcframeworks
  3. Add the downloaded binaries to your project. The binaries can be found in Carthage/Bin directory.

    1. For Objective-C add ROXCore.xcframework.

    2. For Swift add both ROXCore.xcframework and ROX.xcframework.

Carthage (SDK4)

SDK4 only.

To install the iOS package, follow these steps:

  1. In the cartfile, add the following:

    github "rollout/rox-ios"
  2. To install the Carthage dependencies, run the following command in the terminal:

    carthage update --platform iOS

Swift Package Manager

SDK5 only.

To add ROX to an Objective-C project use this repository: https://github.com/rollout/rox-core-spm/.

To add ROX to Swift code, use this repo URL: https://github.com/rollout/rox-spm/.

Manual installation (XCFramework)

SDK5 only.

To install the iOS package, follow these steps:

  1. Select and download the latest ROX.xcframework.zip archive version from the GitHub repository.

  2. Extract the archive into the directory under your application.

  3. Add files to your project in Xcode by selecting the downloaded ROXCore.xcframework and ROX.xcframework.

    1. For Objective-C project add ROXCore.xcframework.

    2. For Swift add both ROXCore.xcframework and ROX.xcframework.

Manual installation

SDK4 only.

To install the iOS package, follow these steps:

  1. If you are already in the manual step screen on the dashboard, click download.

  2. If for some reason you left the installation screen you can go back by clicking on Dashboard > Install Instructions.

  3. Download the zip file and open it. Place the ROX directory under your application.

  4. Add files to your project in Xcode by selecting ROXCore.framework and RoxSdk.xcodeproj.

  5. Remove ROXCore.framework from Linked Frameworks and Libraries.

  6. Click the plus sign (+) under Embedded Binaries and select both ROXCore.framework and ROX.framework.

Add the following lines of code to your application

Swift
Objective-c
import ROX
import ROXCore

public class flags : RoxContainer {
  // Define the feature flags
  let enableTutorial = RoxFlag()
    // Using a simple singleton pattern
    // a single instance should be used and injected to using classes and unit tests
  let titleColors = RoxString(withDefault: "White", variations: ["White", "Blue", "Green", "Yellow"])
  static let INSTANCE = flags()
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

  //Register the flags instance
  ROX.register(container: flags.INSTANCE)

  // Setup the environment key
  ROX.setup(withKey: <ROLLOUT_ENV_KEY>)

  return true
}

flags.INSTANCE.enableTutorial.enabled {
  // TODO: Put your code here that needs to be gated
}

switch flags.titleColors!.value()! {
  case "White":
    print("Title color is White")
  case "Blue":
    print("Title color is Blue")
  case "Green":
    print("Title color is Green")
  case "Yellow":
    print("Title color is Yellow")
  default:
    print("Title color is default - White")
}
#import <ROXCore/ROXCore.h>
@interface flags : ROXBaseContainer
@property (nonatomic) ROXFlag* enableTutorial;
@property (nonatomic) ROXString* titleColors;
@end

#import "MyContainer.h"
@implementation flags

- (instancetype)init {
  self = [super init];
  if (self) {
    self.enableTutorial = [[ROXFlag alloc] init];
    self.titleColors = [[ROXString alloc] initWithDefault:@"White" variations:@[@"Blue", @"Green", @"Yellow"]];
  }
  }
  return self;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        // Register the flag
    [ROX register:[[flags alloc] init]];

    // Setup the environment key
    [ROX setupWithKey:@<ROLLOUT_ENV_KEY>];

    return YES;
}

[flags.enableTutorial enabled:^{
  // start the tutorial
} disabled:^{
  // skip the tutorial
}];

if ([flags.titleColors.value isEqualToString:@"Blue"]) {
    NSLog(@"Title color is Blue");
}
else if ([flags.titleColors.value isEqualToString:@"White"]) {
    NSLog(@"Title color is White");
}
else if ([flags.titleColors.value isEqualToString:@"Green"]) {
    NSLog(@"Title color is Green");
}
else if ([flags.titleColors.value isEqualToString:@"Yellow"]) {
    NSLog(@"Title color is Yellow");
}

@end

Run your application

Running the application

The flag name is automatically added to the CloudBees Feature Management dashboard after running the application.