Setting up user specific preprocessor macros for Xcode

3 Solutions Collect From Internet About “Setting up user specific preprocessor macros for Xcode”

You set the value in the “Preprocessor Macros” Build Settings. Setting “SOME_VARIABLE=${USER}” in the build settings is equivalent to #define SOME_VARIABLE “jappleseed” in your code.

Then in your code you can do this:

#define jappleseed 1
#define sjobs      2

#if DEV_USER == jappleseed
    NSLog(@"Hi Jhonny");
#elif DEV_USER == sjobs
    NSLog(@"Hi Steve");
#endif

Note: This is a contrived example if you really want the string “jappleseed” for use in your code you should be using an Info.plist and not #define

In Xcode 6 (at least) you can include your username as part of the name of the macro in the preprocessor macros section of the Build Settings:

ENV_USER_$(USER)=1 (this will define the macro ENV_USER_myusername)

Then, in your code, you can use

#if ENV_USER_myusername
...
#endif

The =1in the definition may be redundant, since Xcode seems to define the variable as true by default. We put it there just to be on the safe side and be able to use either #if or #ifdef. This way there is no concern that it might be defined, but evaluating to false, in which case #ifdef would still work but #ifwouldn’t. Of course, you might define it to be any value you wish, depending on what you want.

in swift: add DEBUG_$(USER) to “Active Compilation Conditions”

there is no way to assign a value