Why doesn't this code work when compiling an ApplicationTests unit test bundle?
#if TARGET_OS_IPHONE #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #else #import <Cocoa/Cocoa.h> #endif
One of my dependencies has this check and compiles just fine in my main application bundles, but it tries to load <Cocoa/Cocoa.h>
when compiling my ApplicationTests bundle. It's probably just my lack of understanding of Xcode, but I get nervous when my test bundles don't build. Any suggestions?
You need to add
#include <TargetConditionals.h>
source: https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-8A428/TargetConditionals.h.auto.html
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With