Rollout.io - Documentation

iOS SDK

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

Getting started with iOS SDK

Step 1 - Setting up

To setup iOS SDK, follow these steps:

  1. Create a Rollout account. See Signup Page to create an account.

  2. Create an application in the Rollout dashboard.

    • The first time you log into your account, click the Create New App button to create a new app.
  1. Get your environment key.
    • Get the key from App Settings > Environment > Key

Step 2 - Installing the iOS SDK

Initialize the iOS package to your application

For instructions on installing the iOS package, select your installation method:

  • CocoaPods
  • Carthage
  • Manual installation

CocoaPods

To install the iOS package, follow these steps:

  1. In the podfile, add the following:
pod 'ROX'
  1. To install the Cocoapods dependencies, run the following command in the terminal:
pod install

Carthage

To install the iOS package, follow these steps:

  1. In the cartfile, add the following:
github "rollout/rox-ios"
  1. To install the Carthage dependencies, run the following command in the terminal:
carthage update --platform iOS

Manual installation

To install the iOS package, follow these steps:

  • If you are already in the manual step screen on the dashboard, click download.
  • If for some reason you left the installation screen you can go back by clicking on Dashboard > Install Instructions
  • Download the zip file and open it. Place the ROX directory under your application.
  • Add files to your project in Xcode.
    • Select ROXCore.framework and RoxSdk.xcodeproj.
  • Remove ROXCore.framework from Linked Frameworks and Libraries.
  • Click the plus sign (+) under Embedded Binaries and select both ROXCore.framework and ROX.framework.

Add the following lines of code to your application

// Import Rollout SDK
import ROX

// Create RoxFlags in the flags container class
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 = ROXVariant(withDefault: "White", options: ["White", "Blue", "Green", "Yellow"])
    static let INSTANCE = flags()
}

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

  //Register the flags instance with Rollout
	ROX.register("", container: flags.INSTANCE)
  
  // Setup the Rollout environment key
  ROX.setup(withKey: <ROLLOUT_ENV_KEY>)

  return true
}

// Boolean flag example
flags.INSTANCE.enableTutorial.enabled { 
  // TODO: Put your code here that needs to be gated
} 
  
//Multivariate flag example
  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 Rollout SDK
// MyContainer.h file 
#import <ROXCore/ROXCore.h>
@interface flags : ROXBaseContainer  
@property (nonatomic) ROXFlag* enableTutorial;
@property (nonatomic) ROXVariant* titleColors;
@end
   
// MyContainer.m file
#import "MyContainer.h"
@implementation flags

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

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

		// Register the flag with Rollout 
    [ROX register:[[flags alloc] init]];
  	
  	// Setup the Rollout environment key
    [ROX setupWithKey:@<ROLLOUT_ENV_KEY>];
    
    return YES;
}

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

// Multivariate flag example
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

Container class registration and environment key setup

  • You can not call Rox.setup() twice in the same runtime.

Run your application

Running the application

The Flag name is automatically added to the Rollout dashboard after running the application.

Step 3 - Deploying a feature flag

Finding your flags in the Rollout dashboard

After creating feature flags and running your feature code, you can find your flags in the Rollout dashboard.

To find your flags in the Rollout dashboard:

  1. Find your app in the Rollout dashboard
    To switch between apps, click on the app name in the top-left corner of the screen and select the app you want from the pulldown.

  2. Click on Flags on the left side of the navigation panel.

  3. Confirm that your flag is listed in the flag view.

Configuring deployment rules

  1. Go to Rollout's dashboard.
  2. Click on Experiments on the left panel.
  3. Click the Create Experiment button to create a new experiment.
  4. In the New Experiment window:
    • Find the Flag name from the menu, choose it.
    • Click the Set Audience button to continue. The Experiment Details view appears.
  5. Select either True, False, Split or Scheduled. Split allows you to select the percentage of the target group that you want to deploy. Scheduled allows you to schedule a deployment date.
  1. Click Update Audience.

Note:

  • You can not delete the default condition.
  • You can click the Reset link to go back to the state from before you started making changes. Reset only appears when you've made saved modifications.

See Audience for more detailed information.

Updated 2 months ago


iOS SDK


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

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.