TARGET_OS_IPHONE and ApplicationTests

送分小仙女□ 提交于 2019-11-30 17:23:21
James J

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.

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.

It imposes no performance penalty, although it can hurt compile times. That said, it isn't really an issue for Objective C. However, it can really hurt when dealing with C++ classes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!