
PRODUCT FLAVOURING iOS / Build Configurations iOS
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

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
BASEURL = TestDevUrl
BASEURL = TestProdUrl
STEP 5:
Adding different schemes for different flavours.


Edit scheme

After pressing edit scheme you can see a menu to edit present schemes , we will change to new prod scheme , change
Run -> Build configuration -> ReleaseNow 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
Value: $(BASEURL)Key: BaseUrlType: String

STEP 7:
Access value in code using:
print(Bundle.main.infoDictionary?[“BaseUrl”] as! String)
Change the scheme to production and than try it again (do try it on device because in simulator it does work nicely)


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
Targets Support Files -> Pods-<#ProjectName#>In the above folder you will be having two config files with some additional 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
#include “Pods/Target Support Files/Pods-<#project name#>/Pods-<#projectname#>.debug.xcconfig”this is for debug
#include “Pods/Target Support Files/Pods-<#project name#>/Pods-<#projectname#>.release.xcconfig”this is for release
it look like this


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.
