开发者

Tell Xcode to ignore a header for some targets?

开发者 https://www.devze.com 2023-02-02 17:53 出处:网络
I have an Xcod开发者_如何学Pythone project with a mac target and an iOS target.The project contains a class IPhoneOnlyClass which is used in the iOS target only.I have unchecked IPhoneOnlyClass.m from

I have an Xcod开发者_如何学Pythone project with a mac target and an iOS target. The project contains a class IPhoneOnlyClass which is used in the iOS target only. I have unchecked IPhoneOnlyClass.m from the mac target so it doesn't compile that file.

Now IphoneOnlyClass.h contains the line

#import <GameKit/GameKit.h>

When I am compiling for the mac target, Xcode gives me an error:

error: GameKit/GameKit.h: No such file or directory

I could get around this with a #ifdef, but is there a better way? I'd rather tell Xcode to ignore the header altogether when compiling the mac target.


You should not be importing the iPhone-only class headers in your Mac-specific or multi-platform source files in the first place.

If that's unavoidable, then you'll need to use a preprocessor macro, such as TARGET_OS_MAC versus TARGET_OS_IPHONE, to determine when to import the headers for your iPhone-only classes.

Also, make sure you haven't accidentally added any iPhone-only classes to the Compile Sources build phase of your Mac target.


I don't think #ifdef are bad solution. If you look at UIKit header files you will see Apple use a lot of "#if" such as:

#if __IPHONE_4_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED

And

#if TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)

(Last line was copied from NSObjCRuntime.h)


you need to add the framework to your Xcode project.

Frameworks / Linked Frameworks, Add -> Existing Frameworks

for more detailed info, just google add framework to xcode

0

精彩评论

暂无评论...
验证码 换一张
取 消