Xcode schemes to manage different environments in iOS Swift 5
Flavouring helps us to create different environments for our application during development.
Flavouring is very important in order to simplify the code.
e.g - debug url : http://saurabhdev.com
stagging url: http://saurabhstagging.com
live url : http://saurabhlive.com
Now, either we can comment or uncomment the urls according our needs. Or we can setup product flavouring which is the best way to deal with multiple app environments.
Below is the step by step guide to add flavouring in the project.
Open Xcode, create a new project and name it Flavouring.
Now click on project name on the top left and select Project.
Then click on Info and click on add (+) button under Configurations.
Name it staging. Now we have three configurations setup in our project.
Now go to your Project Targets > Build Settings >> Swift Compiler - Custom Flags
Now under Active Complication Conditions, rename the conditions. Note: These names will be used inside our application for flavouring
Now we have done the initial setup.
Move to ViewController.swift. I have created a enum for different environments. Please add below code to your ViewController.
Now we can check our code by changing environment in the Edit scheme. Click on your Project name on the top and select Edit Scheme.
Now go to info and change build configuration to stagging.
Run the application, and you will see Staging Url printed in the console. You can select whatever environment you need to work on by clicking on Edit scheme and repeat steps as shown above.
That's all about Product Flavouring.
Cheers!
Comments
Post a Comment