Library for both iOS and OS X apps? [closed]

╄→尐↘猪︶ㄣ 提交于 2019-11-28 21:14:43

问题


For a while now I have been killing spare time by creating a 2D game programming toolkit/library. It is written in Objective C, and consists of an OpenGL rendering system and a whole bunch of AI, physics code, a bunch of specialized containers and other game related stuff. Apart from the OpenGL based View mechanism (obviously), most of this code should be easily portable to iOS since it only uses the Foundation Framework and that framework appears to be implemented on iOS. So far I have only been testing the various components using a Cocoa NSOpenGLView but now I want to create a OS X/iOS library.

My Question is:

What's the best strategy for creating an Objective-C library that can be integrated into either iOS or OS X applications?

The Xcode 'New Project' dialog offers only:

iPhone OS; Library:
- Cocoa Touch Static Library.

Mac OS X, Framework and Library:
- Cocoa Framework
- Cocoa Library
- Bundle
- BSD C Library
- STL C++ Library
- JNI Library

At first glance none of these seems to be intended for creating a library that can be integrated into either OS X or iOS applications.


回答1:


Well, I finally found the correct set of Google search terms, so to answer my own question (DOH!), it seems to be possible to share code, at least between iPhone apps and possibly also iPhone and OS X apps within certain limits. You have to create a 'static library' and use 'cross-project references':

http://www.clintharris.net/2009/iphone-app-shared-libraries/
http://www.amateurinmotion.com/articles/2009/02/08/creating-a-static-library-for-iphone.html
http://zetetic.net/blog/2010/02/15/building-static-libraries-to-share-code-on-iphone-and-mac-os-x-projects/
http://weston-fl.com/blog/?p=808

Haven't tested any of this yet but it looks promising.




回答2:


You can do this with Targets.

Create a new project for a Cocoa Library. Then add a new target for a iOS Static Library. As you create new files ensure they're added to the appropriate targets (i.e. presumably both in your case) and set per-target build settings as required.

Projects using your library on the different platforms will need to link against the appropriate product but you won't need to duplicate your code.



来源:https://stackoverflow.com/questions/3745907/library-for-both-ios-and-os-x-apps

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