How do I define preprocessor macros in Xcode 4?

The Crazy Chimp picture The Crazy Chimp · Oct 21, 2011 · Viewed 20.9k times · Source

I have two targets set up for my app (a lite version and a pro version) and I want to integrate some subtle differences in the code for each of them (e.g. the pro version will not show any iAd banners).

I have been looking around and I see the easiest way to do this is through the use of preprocessor macros. The issue I'm facing is how to set them up in Xcode 4. I want to set up a macro called 'PRO_VERSION' in one target & 'LITE_VERSION' in the other.

Below is an example of how I intend to use them:

#ifdef PRO_VERSION
    // Hide ad banners
#else
    // Show ad banners
#endif

Answer

Robin Summerhill picture Robin Summerhill · Oct 21, 2011

The build setting you need to change is called 'Preprocessor Macros' and it can be found in the 'Build Settings' tab of the Project Settings pane (use the search box to find it). Select each target in turn in the left-hand side of the Project Settings pane then modify the Preprocessor Macros setting.

The setting is specified as a space-separated list of preprocessor macros in the form 'foo' or 'foo=bar'.