skip to Main Content

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?

2

Answers


  1. Wrapped the Toggle in #if DEBUG

    #if DEBUG
    Toggle(isOn: .constant(true), label: {
        Text("Label")
    })
    #endif
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search