PRODUCT FLAVOURING iOS / Build Configurations iOS

Lovekesh Bhagat
Jul 23, 2017 · 4 min read

In iOS we usually face issues related to product flavouring , how we can manage builds for different types of environments (development , production or staging). To manage builds we can use xcconfig files.


What are xcconfig files ?

A build configuration file, also known as an xcconfig file, is a plain text file that defines and overrides the build settings for a particular build configuration of a project or target.


How we can use them to manage builds?

Below is the step by step tutorial to create a awesome system to manage build types.

STEP 1:

Create a iOS project and add an Configuration folder (or whatever you want to name it) outside your target folder

Create configuration folder

Add configuration folder to your project

STEP 2:

Add configuration files to your project (to configuration folder).

You can add as many configuration according to your needs we will add two one for development and one for production

Step 3:

Map Configuration files with project configurations

Select Project -> Info -> Configurations

Select Debug mode for and you can see DevMode config and ProdMode config , select one of them according to your need , we will select DevMode for debug and ProdMode for Release

STEP 4:

Add properties to config files you want to access for different flavour

Dev Mode
Prod Mode

STEP 5:

Adding different schemes for different flavours.

Add New Scheme

Edit scheme

Edit scheme

After pressing edit scheme you can see a menu to edit present schemes , we will change to new prod scheme , change

Now if you run with prod scheme it will run with

STEP 6:

Add corresponding properties to plist

We will add same properties to plist with the help of which we can access these properties in our code

STEP 7:

Access value in code using:

DevMode

Change the scheme to production and than try it again (do try it on device because in simulator it does work nicely)

You will see production url

Now you can add properties to config files and easily access on the basis of schemes.


Pods handling

In case you are working with pods , so you need to include pods config files as well in the configuration files.

For both development and production environments.

You will come across error because the config files for the pods are missing to resolve this problem check your code , you must be having

In the above folder you will be having two config files with some additional files

Pods config files

Now we can include these files in the corresponding files config files.We need to include relative pod path not absolute path for example

this is for debug

this is for release

it look like this

Debug
Release

Working with URL’s

If you are working with the URL’s than use $() as escape character. I was trying hard to find out a solid solution for this but not able to find out , will update it as soon as i will found a solution for this.

Thanks and do write comments for suggestions , reviews or any doubts.I will respond quickly.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade