Why doesn\'t this code work when compiling an ApplicationTests unit test bundle?
#if TARGET_OS_IPHONE
#import
#import &
You need to add
#include <TargetConditionals.h>
source: https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-8A428/TargetConditionals.h.auto.html
Both work well
#import "TargetConditionals.h"
#import <Foundation/Foundation.h>
<Foundation/Foundation.h>
|
└-#import <Foundation/NSObjCRuntime.h>
|
└- #include <TargetConditionals.h>
|
└- defined TARGET_OS_IPHONE
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.