TARGET_OS_IPHONE and ApplicationTests TARGET_OS_IPHONE and ApplicationTests xcode xcode

TARGET_OS_IPHONE and ApplicationTests


The simplest solution is to move the #import <Foundation/Foundation.h> statement out if the #if condition and replace Cocoa with AppKit like this:

#import <Foundation/Foundation.h>#if TARGET_OS_IPHONE   #import <UIKit/UIKit.h>#else   #import <AppKit/AppKit.h>#endif

The Foundation umbrella header imports the NSObjCRuntime header which in turn imports the TargetConditionals header.


I had a similar problem: TARGET_OS_IPHONE isn't defined when building a static library. My solution was to add "-DTARGET_OS_IPHONE" to the "Other C Flags" section of the target build options.