Monday 8 April 2019

Add Feature Toggle to Settings through Settings.bundle

This guide will take you though how to add feature toggle to you app. The toggle in Settings then will allow to turn on/off a feature or switch between two versions without generating different build, which will be helpful for refactoring and testing.

Check demo code at Github:
https://github.com/Sylvia-YiyinShen/FeatureToggleDemo

1. New File in Xcode, choose Settings.bundle. 
    The Settings.bundle will be created and automatically added to Build Phases
2. Modify Root.plist inside Settings.bundle
    There will be several preference items automatically generated by default and visible through Settings.







Check Apple's docs to see all the control type:

3. Next we need a manager to grab the preference item value from Settings.
    Each preference item value is stored in UserDefault, we can always get the updated value via  the key which is Identifier in Root.plist
  




Now we can just check enableUpdateLabel bool value for different implementation. 

Try go to settings and toggle the Enable Update Label option. Then kill the app and re-run.

No comments:

Post a Comment