3

I'd like to set the value of a variable in my Xcode project based on a command-line argument passed into xcodebuild.

For instance, I'd like to run xcodebuild -project MyProj.xcodeproj -alltargets -configuration Debug ENV=2 and have it set a string named "rootUrl" in my code.

I'm expecting something similar to the following in my code:

#if (ENV == 2)
static NSString * const rootUrl = @"staging.url.com";
#elif (ENV == 1)
static NSString * const rootUrl = @"dev.url.com";
#else
static NSString * const rootUrl = @"prod.url.com";
#endif

But no matter the value of ENV I pass into xcodebuild, rootUrl always gets set to "staging.url.com".

I also have ENV=$(ENV) set in my Preprocessor Macros under Build Settings.

How can I achieve the desired behavior?

2 Answers 2

4

Try replacing ENV=2 with GCC_PREPROCESSOR_DEFINITIONS="ENV=2" on your command line. I don't think you need to set the 'Preprocessor Macros' in the Build Settings as it will be overridden anyway.

See xcodebuild - how to define preprocessor macro? for more information.

Sign up to request clarification or add additional context in comments.

Comments

0

If I remember it right it is the -D flag you want.. that specifies Preprocessor macros.. so -DENV=2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.