嵌入了iOS项目的OSX项目-未找到UIKit.h [英] OSX project with an iOS project embedded - UIKit.h not found

查看:329
本文介绍了嵌入了iOS项目的OSX项目-未找到UIKit.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个OSX项目和一个iOS子项目.该子项目使用UIKit.h,但是即使该子项目将UIKit框架添加到了使用库链接二进制文件"部分,我仍然收到错误消息:

I have an OSX project with an iOS subproject. The subproject uses UIKit.h, but even though the subproject has the UIKit framework added to the Link Binary with Libraries section, i still get the error saying:

找不到词法或预处理器问题错误UIKit/UIKit.h文件

Lexical or Preprocessor Issue error UIKit/UIKit.h file not found

我该如何解决?

推荐答案

听起来像您只需要一些条件编译:

Sounds like you just need some conditional compilation:

我有一个为OSX和iOS构建的项目,它们共享源代码.我有一个名为SysInfo.h的头文件,该文件的顶部为

I have a project that builds for both OSX and iOS that shares source code. I have a header file called SysInfo.h that has this at the top:

#import <TargetConditionals.h>

#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
#define SYSINFO_OSX 1
#else
#define SYSINFO_IOS 1
#endif

(以及此处不相关的其他内容)

(as well as other stuff that isn't relevant here)

然后可以像这样使用它:

and can then use it like this:

#import "SysInfo.h"

#ifdef SYSINFO_OSX
#import <Cocoa/Cocoa.h>
#else // !SYSINFO_OSX
#import <UIKit/UIKit.h>
#endif // SYSINFO_OSX

当然,这只是冰山一角,因为您将需要使用几乎相同的方法来确保在正确的平台上使用正确的API.

Of course, this is just the tip of the iceberg as you will need to ensure you use the correct APIs on the correct platform, using much the same approach.

这篇关于嵌入了iOS项目的OSX项目-未找到UIKit.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆