A feature switching/toggling/flipping library for ObjectiveC.
A gem command line tool for generating the Features.plist
& FlipTheSwitch+Features.{h,m}
categories to help with the corresponding Pod.
We have a a new feature we've been working on, AmazingFeature
, and we've been building it inside a branch.
Now has come the time to finally merge it back in. This then takes us the next day, as the MyApp.xcodeproj/project.pbxproj
file has a lot of conflicting changes, and we get things wrong a lot before we get them right.
We weren't able to rebase often, as multiple people were working on this branch, and so we also had to keep regularly merging in all of the other changes from the rest of the team, constantly losing focus of our goal.
We finally have it all merged and then... everything breaks!
The way to avoid all of these constant merges/rebases/context switches is to always have our code in the master
branch, but we didn't want to affect the rest of the team while they released QuickerFeature
in the next release cycle.
How can we get the benefits of working on master
branch, while still not worrying about breaking the other features while we build AmazingFeature
?
With FlipTheSwitch, we can choose different code paths at runtime:
self.newFeatureButton.hidden = [[FlipTheSwitch sharedInstance] isFeatureEnabled:@"new_feature"];
The features can be enabled/disabled at runtime:
[[FlipTheSwitch sharedInstance] enableFeature:@"new_feature"];
[[FlipTheSwitch sharedInstance] disableFeature:@"new_feature"];
[[FlipTheSwitch sharedInstance] setFeature:@"new_feature" enabled:YES];
All enabled features will persist between app loads through NSUserDefaults
.
The features can defaulted to enabled/disabled via a plist file Features.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>enabled_feature</key>
<true/>
<key>disabled_feature</key>
<false/>
</dict>
</plist>
If you install the gem, you will be able to use the Command-Line-Interface.
The CLI consists of 3 commands:
plist
- creates aFeatures.plist
file for enabled/disabled features like that mentioned above.settings
- creates aSettings.bundle
used by the OS settings. These can then be used to enable/disable the features at runtime.category
- createsFlipTheSwitch+Features.{h,m}
files for features, thus giving compile-time checks for adding/removal of new features. e.g:
/* AUTO-GENERATED. DO NOT ALTER */
#import <FlipTheSwitch/FlipTheSwitch.h>
@interface FlipTheSwitch (Features)
+ (BOOL)isAwesomeFeatureEnabled;
+ (void)enableAwesomeFeature;
+ (void)disableAwesomeFeature;
+ (void)setAwesomeFeatureEnabled:(BOOL)enabled;
@end
The features, along with their default enabled/disabled state, are read from a features.yml
file. e.g.:
default:
awesome_feature: Yes
In order to avoid typing in the same options all the time, you can create a .flip.yml
file for the default options, e.g.:
input: features
environment: development
category_output: Classes/Extensions
For more information, run flip-the-switch help
Add pod 'FlipTheSwitch'
to your Podfile
Add gem 'flip_the_switch'
to your Gemfile
FlipTheSwitch is available under the MIT license. See the LICENSE file for more info.