XCode: 7 Steps to Easily Switch Between Multiple Environments
— posted on February 4, 2015 10:13 AM
Share this to

Step 1: Create a new project
When starting out a new project, fill in the empty fields with your project details eg.Product Name
: Your project name
Organization Name
: Your organization name (Can be left blank)
Organization Identifier
: com.company
[caption id="attachment_5999" align="aligncenter" width="1454"]
Next
. Choose your project location and click Create
. Xcode will then set up your new project and open the editor for you.
Step 2: Create Build Configurations
Firstly, navigate to your project info. And find theConfigurations
section. Your Configurations
option will have a Debug option and Release option inside.
[caption id="attachment_6005" align="aligncenter" width="1842"]
duplicate the "Debug" configuration
to create a new configuration.
[caption id="attachment_6008" align="aligncenter" width="1588"]


Step 3: Create User-defined Build Settings
Typically, we will create a user-defined settings for Bundle ID, app icon names, Facebook App ID, etc. So we will be able to assign different Bundle ID, icon names or Facebook App ID for different Build Configurations. To do so, navigate to project build settings, click on the Add button(+) and add User-defined Setting. In this example, I create 3 different user-defined setting;BUNDLE_ID
, NAME_SUFFIX
and FB_APP_ID
.
[caption id="attachment_6013" align="aligncenter" width="1830"]

Step 4: Modify Info.plist file
All the user-defined settings defined in the previous step will be used in the project'sinfo.plist
. Make sure you have done all the previous steps before proceeding.
Modify your info.plist
by inserting the value defined in user-defined settings. So, for example if you define BUNDLE_ID
in user-defined settings, modify your bundle identifier in info.plist
with $(BUNDLE_ID)
.
Bundle Identifier : $(BUNDLE_ID)
Bundle display name: Demo App $(NAME_SUFFIX)
FacebookAppID: $(FB_APP_ID)
If your project's info.plist
is missing some of the fields, simply add a new one.
[caption id="attachment_6016" align="aligncenter" width="1840"]
Step 5: Create Schemes with Build Configurations
Each of our app builds needs one Scheme, so we will create 3 Schemes; DemoAppStaging, DemoAppProduction and DemoAppStore, for staging build, production build and App Store build respectively. Click on your project active scheme located on top left of the editor and click on "manage scheme". Refer the image below if you can't find it. [caption id="attachment_6018" align="aligncenter" width="962"]

Shared
option so that these changes are added on Git repository.
[caption id="attachment_6020" align="aligncenter" width="1450"]
Step 6: Edit Schemes
Then, edit the schemes based on the build configurations. For example, DemoAppStaging use Debug Staging and Release Staging Build configurations. Make sure that you have edit each of the build configurations forBuild
, Run
, Test
, Profile
, Analyze
and Archive
.
[caption id="attachment_6021" align="aligncenter" width="1788"]
Schemes | Configurations |
---|---|
DemoAppStaging | Debug Staging |
Release Staging | |
DemoAppProduction | Debug |
Release | |
DemoAppStore | App Store |

Step 7: Define Preprocessor Macros
To easily switch the Base URL of API server, we can add a preprocessor macros to define the target's environment. For exampleSTAGING=1
for Staging schemes. To add the macros, search for Preprocessor Macros
under the Apple LLVM6.0 - preprocessing
section. Then add STAGING=1
in Debug Staging and Release Staging.
[caption id="attachment_6027" align="aligncenter" width="1838"]
Share this to