How to Configure Build Settings for Multiple Environments in the Xcode Project Editor
When developing a system, you may want to use different settings depending on the environment when deploying your program to QA or production.
Here, we'll explain how to configure environment-specific build settings in the Xcode Project Editor.
This assumes that Build Configurations and Schemes have already been created. If not, please return to the How to Manage Environment Settings in Xcode index and add them first.
Priority of Build Settings in Xcode
In Xcode, you can define build settings in multiple places, so there's a priority order that determines which values are applied.
The priority, from highest to lowest, is as follows:
- Target-level Build Settings
- Config file mapped to the Target
- Project-level Build Settings
- Config file mapped to the Project
- Platform defaults
Later, we'll look at how to configure environment-specific settings at the Target level and how to set values using config files.
You can check which values are ultimately effective in the Project Editor, as shown below.
The value displayed under Resolved is the final value that will be applied to that build setting key.
However, it's a bit tricky—just because a build setting is defined here doesn't necessarily mean it will always be used in the final build.
For example, even if the Product Bundle Identifier is defined at the Target-level Build Settings, if the value in info.plist has been changed from $(PRODUCT_BUNDLE_IDENTIFIER) to something else, that value will take precedence.
In short, the Resolved value shown here is what will be applied to the key PRODUCT_BUNDLE_IDENTIFIER.
Configuring Environment-Specific Build Settings in the Project Editor
Now, let's configure environment-specific values at the Target level in the Project Editor.
For example, let's set different Bundle IDs for each environment.
In the Project Editor, click the project name under TARGETS, select the Build Settings tab, and search for Bundle.
Click the arrow next to Product Bundle Identifier, and you'll see the values for each Build Configuration.
For the Development configuration, append .dev to the Bundle ID, and for the QA configuration, append .qa.
Now, assuming info.plist hasn't been changed, when you switch the build scheme and run, a different Bundle ID will be used for each environment. This allows you to install environment-specific apps on the same device.
That's how to configure environment-specific build settings in the Xcode Project Editor.