I want to add a new #define
macro to my app, but only for certain schemes, like a beta scheme. What is the best way to do this? I know that when you are running the app in test (i.e. in simulator) it adds a DEBUG=1 macro, but I can't figure out how to add more ones.

- 5,753
- 72
- 57
- 129

- 14,517
- 25
- 92
- 153
3 Answers
The best way is to use Xcode configuration files.
Add a couple of files named Beta.xcconfig
and Distribution.xccconfig
(or something like that) and add your macros for each kind of build.
Beta.xcconfig:
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) BETA=1
Distribution.xcconfig.
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) BETA=0
You can add the files easily with the new file dialog:
Then, you need to map each file to a build style. Got to top level project, project settings (right above targets) and click "Info" section:
In your code you can use the macro as always:
#if BETA
// do something only in beta
#endif
If instead of assigning a value you just define the macro you should use #ifdef
.
If you use several macros you may need to check that everything is working as expected looking in your build logs:

- 19,551
- 4
- 71
- 68
-
Thanks. But your answer wasn't clear **which** project info tab to go to, since there are a few. Thankfully I was able to figure it out, but you should update your (excellent) answer to say that it's for the whole project - not for any subprojects. – Jason Nov 25 '12 at 06:47
schemes are only executing build configurations
macros can only be set for build configurations
make a new build configuration AND a new scheme to use it
it is a bit inconvenient :/

- 49,552
- 17
- 113
- 135
The alternative (that I used) would be in the build settings for your project or target.
1) Go to Project -> Target -> Build Settings
2) Search for "preprocessor macros"
Now you should be able to see all schemes defined for that project and add whatever preprocessor macros you like. Just remember to leave the $(inherited). Also you probably want to keep all the other defined macros, as in my case I had the COCOAPODS=1 definition.

- 2,318
- 18
- 20