What #defines are set up by Xcode when compiling for iPhone

It’s in the SDK docs under “Compiling source code conditionally”

The relevant definitions are TARGET_OS_IPHONE (and he deprecated TARGET_IPHONE_SIMULATOR), which are defined in /usr/include/TargetConditionals.h within the iOS framework. On earlier versions of the toolchain, you had to write:

#include "TargetConditionals.h"

but this is no longer necessary on the current (xCode 6/iOS8) toolchain.

So, for example, if you want to only compile a block of code if you are building for the device, then you should do

#if !(TARGET_OS_SIMULATOR)
...
#endif

Leave a Comment