简体   繁体   English

链接UIKit和AppKit

[英]Linking both UIKit and AppKit

I am trying to create a base object which can used on both the iPhone and OS X as a datasource. 我正在尝试创建一个可以在iPhone和OS X上用作数据源的基础对象。 I would therefore have a header file with statements such as: 因此,我将拥有一个带有以下语句的头文件:

#ifdef TARGET_OS_IPHONE
#import <UIKit/UITableView.h>

@interface DataObject : NSObject<UITableViewDataSource>
#endif

#ifdef TARGET_OS_MAC
#import <AppKit/NSTableView.h>

@interface DataObject : NSObject<NSTableViewDataSource>

#endif

My current Xcode project is using a standard Apple iPhone template. 我当前的Xcode项目正在使用标准的Apple iPhone模板。 My issue is when I select "Link Binary With Libraries" under the "Build Phases" tab I am only seeing iPhone related frameworks. 我的问题是,当我在“构建阶段”选项卡下选择“将二进制文件与库链接”时,我只会看到与iPhone相关的框架。

Of course I can select other and then browse, but I have no idea where AppKit.Framework lives. 当然,我可以选择其他,然后浏览,但是我不知道AppKit.Framework的位置。 Can anyone point out where I can find this framework or how I can have a project link to both UIKit and AppKit 谁能指出我在哪里可以找到这个框架,或者我如何可以将项目链接到UIKit和AppKit

Can I suggest a slightly different design? 我可以建议稍微不同的设计吗?

Your DataObject should link against only Foundation, which exists on both iOS and Mac OS X. It includes no methods for either of the data sources. 您的DataObject应该仅链接到iOS和Mac OS X上都存在的Foundation。它不包含任何用于数据源的方法。

Then in your iOS app target, you have a category on DataObject that implements the UITableViewDataSource methods and in your OS X application target, you have a category on DataObject that implements the NSTableViewDataSource methods. 然后,在iOS应用程序目标中,在DataObject上具有实现UITableViewDataSource方法的类别,而在OS X应用程序目标中,在DataObject上具有实现NSTableViewDataSource方法的类别。

@interface DataObject(NSTableViewDataSource) <NSTableViewDataSource>

The user interface code in your iOS and OS X apps will be so different that you will need different targets anyway and they each link against the relevant SDK. iOS和OS X应用程序中的用户界面代码将是如此不同,以至于您仍然需要不同的目标,并且它们各自链接到相关的SDK。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM