Flavoring for different build modes in iOS📱

Pranav Singh
3 min readFeb 3, 2024

--

https://dev.to/leon_arantes/react-native-multiple-environments-setup-schemaflavors-3l7p

What is flavoring

In iOS development, flavoring refers to creating different versions of an app with specific features or branding for different purposes or different building modes, all based on a common codebase. Here we will implement flavoring for different building modes only (in this example we will be working with Debug and Release).

Why is flavoring required?

Flavoring in iOS isn’t a strict necessity, but it’s incredibly useful. The requirement for flavoring in our iOS project is to smoothen the development process by creating distinct versions that can be easily switched between environments. This allows for faster development without the need to manually adjust server settings and build modes each time.

How to achieve it ?

The solution is to create two different schemas, and connect config files(containing different environment variables) and info.plist of both the environments.

As an example, value of SERVER_TYPE will be taken from the config file of the current environment, via info.plist and ServerConfig.

Now let’s actually achieve it!!…... 🚜

Step 1 : Create configurations files(.xcconfig) as per your requirement (generally we make different config file for different schemas).

Step 2 : Create info.plist files as per your requirement.

Step 3 : Add/Edit the configuration from the configurations in your xcconfig inside the info setting and connect both xcconfig in the respective environment(config for Pod will be installed automatically)

Step 4 : Connect both info.plist in the respective environment. You should set the unique bundle identifier if you want to keep apps from different environments simultaneously in your iOS device.

Step 5 : Open schemes via any of the option below

  • Go to Product -> Schemes->Choose Scheme
  • Press ^ + 0 (control + Zero) in keyboard
  • Directly clicking on button shown below

Step 6 : Create/Edit the schemes to connect them with the required environment. In the build configuration drop down, we can select the desired environment

Step 7 : Choose the schema and run/build/archive the app from Step 5.

For accessing the values of the configuration file a singleton class is created with the name ServerConfig, having only getter properties.

The use-cases of above code will be as follows :

let API_ID = ServerConfig.shared.WEATHER_API_ID
let API_URL = "https://some-weather-api/forecast?appid=\(API_ID)"

There are multiple ways to implement flavoring, based on our requirements. This article primarily focuses on build flavoring, specifically when we want to simultaneously use both the debug and release builds of our app on the device. Btw here the app which I have taken in example —

🧡 DO COMMENT IF YOU FACE ANY CHALLENGES TO IMPLEMENT — HAPPY TO HELP 🧡

--

--