Xcode schemes to manage Staging Production environment in Swift and Objective-C

Virender Verma
3 min readMay 8, 2020

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 both schemes, need to set configuration. If I don’t do this then further steps will not work. Under Run, Test and Analyze I am setting Debug configuration and for Profile, Archive I am setting Release type of configuration.

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.

You can give any name whichever you want
Add a property Bundle display name and add value which you have defined above. In my case, I have defined it as APP_NAME so I am setting it 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

After this when you run the app for both schemes, two different apps will be shown in the simulator.

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.

Set Swit Compiler — Custom Flags

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

this is used for objective-c code

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.

--

--