Krejko
Krejko

Reputation: 931

Set build variable in scheme instead of target

I am currently working on an iOS project in XCode that uses configurations to specify the different API environments my app can connect to. Additionally, I use targets to override one of my project configuration's user-defined values to specify a particular configuration file to use in the app. However, this is the only value that changes in the target. I work with multiple different configuration files (maybe 10 to 20 at a time) and creating a new target for each file to update one value seems clunky.

My question: Is there a way to pass this one value in from the scheme instead of setting it in the target?

I have seen that there is a pre-build script that can be run but I have not yet had any success exporting environment variables.

CONFIG_FILE="My Config File"
export CONFIG_FILE

I have also seen that some people have had success using PlistBuddy to write the values into the info.plist file during the pre-build phase of the scheme. This may be an option as well although it would require I redo a lot of my build process. I wanted to see if there was any other options before heading down this path.

Thanks for the help.

Upvotes: 4

Views: 3514

Answers (1)

Krejko
Krejko

Reputation: 931

I was able to do this by using a .xcconfig file that is updated during my pre-build action in my scheme.

I used this tutorial to learn how to set up the project: http://www.jontolof.com/cocoa/using-xcconfig-files-for-you-xcode-project/

Upvotes: 2

Related Questions