Which conditional compile to use to switch between Mac and iPhone specific code?

You’ve made a mistake in your observations. 🙂

TARGET_OS_MAC will be 1 when building a Mac or iPhone application. You’re right, it’s quite useless for this sort of thing.

However, TARGET_OS_IPHONE is 0 when building a Mac application. I use TARGET_OS_IPHONE in my headers all the time for this purpose.

Like this:

#if TARGET_OS_IPHONE
// iOS code
#else
// OSX code
#endif

Here’s a great chart on this:
http://sealiesoftware.com/blog/archive/2010/8/16/TargetConditionalsh.html

Leave a Comment