Adding a Preprocessor Definition via a Xcode Scheme Adding a Preprocessor Definition via a Xcode Scheme ios ios

Adding a Preprocessor Definition via a Xcode Scheme


Worse case scenario you can do a pre-build script for the scheme. You'll have to include the script for every scheme though:

I would prefer to attach it to a Configuration:

Then you can easily add preprocessor macros for the various configurations, like I have here for Debug:

The <ProjectName>_Prefix.pch file is a great place to put macros that effect the whole program, like I have here:

In my example we're effectively turning off console output when not in debug mode, providing a little speed boost.


To meet my requirement of allowing schemes to set preprocessor definitions, the best solution I have come up with is to have scheme pre-action and post-action scripts modify a xcconfig file. This file, in turn, updates the build configuration, setting the preprocessor definitions and will even allow me to define preprocessor definitions to conditionally modify the info.plist. If anyone else goes down this route, make sure you take into account how this file is handled by source control.

This article's question and associated answers was helpful to me: How to append values in xcconfig variables?


How about defining multiple targets and defining pre-processor macros in the target-specific build options? Then you need only have one scheme, and you can build all the targets in one shot, all with their own specific build configurations.