Xcode schemes to manage Staging Production environment in Swift and Objective-C
As a developer, Xcode builds schemes give you the ability to deliver different versions of the same code with small tweaks for different environments.
Xcode schemes can help you to setup DEV, UAT and Production environment properties like Server URL, App Name, App Icons, Bundle ID, Info.plist file or You can set up free version / paid version with few line of tweaks.
So without wasting time let’s start with the example cause talk is cheap 😉.
Initially, your Project will look like this
I am going to set up two types of schemes
1. Staging
2. Production
Click on the plus icon and make a duplicate of Debug and one of Release, after doing this it will look like below
After this, I will create schemes for staging and production under Product -> Scheme -> Manage Scheme
For setting app name according to the selected scheme, I am defining a user-defined setting under the Build Settings tab name as APP_NAME.
After completing this step when you run the app you will see Display name as per the selected type of scheme.
Now let us try to change the bundle identifier for each scheme
In case you want to change app icons as well, you may do so under Build Settings.
Now we shall move onto the code where we define the URL or other settings as per the selected scheme type. This is also quite easy to setup.
You can set other property values similarly and your app will select the respective server URL as per the selected scheme type i.e. staging or production.
In case you’re working with an Objective C project, you might not see the Swift compiler custom flags.
To solve this we need to set Preprocessor Macros as follow
And in your Objective-C file, you can check like below
So as you can see configurations and schemes can be a life saviour when you have multiple environments/settings for the same App.