简体   繁体   中英

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. 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. My issue is when I select "Link Binary With Libraries" under the "Build Phases" tab I am only seeing iPhone related frameworks.

Of course I can select other and then browse, but I have no idea where AppKit.Framework lives. Can anyone point out where I can find this framework or how I can have a project link to both UIKit and 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.

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.

@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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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