Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining Settings bundle based on the build configuration

I have defined my Root.plist inside Setting bundle which appears in the device settings. Now, I want it to display different options based on the kind of environment I build the project on.

I have defined a TEST and PROD schemes (different build configuration) in XCode and I want Root.plist to be defined differently for these build configuration. How can this be done?

Can we have 2 plists defined and link them with different build configuration or can we modify the root.plist at the compile time based on the build configuration or scheme chosen.

Please advise.

like image 306
Abhinav Avatar asked Jul 06 '12 17:07

Abhinav


People also ask

What is build configuration in Xcode?

A build configuration file is a plain-text file you use to specify the build settings for a specific target or your entire project. Build configuration files make it easier to manage build settings yourself, and to change build settings automatically for different architectures and platforms.

How do I change my build settings in Xcode?

Choose the project in the Project Navigator on the left. Select the Configurations target from the Targets section and click the Build Settings tab at the top. The Build Settings tab shows the build settings for the Configurations target. It's possible to expand this list with build settings that you define.

How do I save build settings in Xcode?

You can do this by importing it under your Project's Info tab, under Configurations. Save this answer. Show activity on this post. XCConfig files are certainly the way to go for sharing build settings across multiple targets or even projects.


2 Answers

I have worked it out this way:

1) Add 2 settings bundle (one for test and one for prod) to the project and add them to the target.

2) Add a Run script on the Runner target to selectively copy the required Settings bundle into the build file.

if [IS_PRODUCTION]; then
cp -r ${PROJECT_DIR}/Settings/Prod/Settings.bundle ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
fi

if [IS_TEST]; then
cp -r ${PROJECT_DIR}/Settings/Test/Settings.bundle ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
fi

3) Once done, just run on different schemes to see the desired results.

like image 85
Abhinav Avatar answered Nov 11 '22 09:11

Abhinav


I do something similar to @Abhinav, but instead of using a run script, I just use the Target Membership section of the File inspector to determine which target uses which Settings.bundle.

Settings Bundle Target Membership

like image 31
Greg Avatar answered Nov 11 '22 09:11

Greg