I want to create a feature toggle in the settings bundle of our app. So, if we on/off the toggle, we can show/hide a specific feature that's currently being developed. But, I don't want to show the toggle option on the production settings yet. Users who download the app don't need to see this feature. So, How do I hide the toggle if its on production mode?
-
Does this answer your question? [Condition #if DEBUG else if PRODUCTION not working in Swift](https://stackoverflow.com/questions/58876224/condition-if-debug-else-if-production-not-working-in-swift) – Martheen Jun 22 '21 at 01:20
-
@Martheen I checked out the same code. My doubt is when the app launches, it shows everything in my plist. For instance, the toggle I setup in the plist will be there during launch. What code should I write in the else condition to hide the toggle setup the settings bundle? – user1749073 Jun 22 '21 at 01:31
2 Answers
Wrapped the Toggle in #if DEBUG
#if DEBUG
Toggle(isOn: .constant(true), label: {
Text("Label")
})
#endif

- 103
- 7
I would recommend moving to use a Feature Flag tool that supports iOS such as LaunchDarkly or DevCycle.
This way you can not only control if a feature is on or off in production but also control which specific user or group of users can see that feature.
You can also integrate the Feature Flag into your back end as well so that users of a specific version of your application can get specific APIs or data sets.
In this example, you would enable Feature Flags (using DevCycle) in your application. Docs are at: https://docs.devcycle.com/docs/sdk/client-side-sdks/ios
Then if you wanted to toggle on a feature, such as an option on an admin screen you would wrap the code this way:
let user = try DVCUser.builder()
.isAnonymous(true)
.appVersion("1.1.1")
.build()
guard let client = try DVCClient.builder()
.environmentKey("<DEVCYCLE_MOBILE_ENVIRONMENT_KEY>")
.user(user)
.build(onInitialized: nil)
let boolVariable: DVCVariable<Bool> = client.variable(key: "new-feature", defaultValue: false)
You can then turn on this Feature Flag for users who have appVersion 1.1.1, and it will be off for all other users.

- 41
- 5