Feature Toggles

Episode #153 | 8 minutes | published on January 22, 2015
Subscribers Only
In this episode I cover configuring your Xcode project to conditionally include or exclude a feature, in case there is a feature you can't have in the App Store, or perhaps something that isn't quite ready yet.

Update: As "Deny" says in the comments:

You can use preprocessor macros, but you must fill it in "Swift compiler - Custom Flags" section in project settings

Thanks! I was unaware of this setting.

Episode Links

Take a look at the configuration in the xcodeproj above for the settings. Then expose this configuration variable as a property in an Objective-C file:

// Features.h
#import <Foundation/Foundation.h>
const BOOL FeatureAEnabled;
#import "Features.h"

const BOOL FeatureAEnabled = YES;
const BOOL FeatureAEnabled = NO;

Make sure you've enabled a bridging header so you can include this file:

// Bridging-Header.h
#import "Features.h"

Then you can use this in your Swift files:

class WindowController: NSWindowController {
    dynamic var featureAEnabled: Bool {
        return Bool(FeatureAEnabled);

And with this being a Mac app, you can bind your Hidden bindings to this property (using the NSNegateBoolean value transformer).

There are many ways of accomplishing this same technique. If you have a different (or better) way of handling this, please leave a comment.

blog comments powered by Disqus