Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 439
os x nerd Avatar asked Sep 19 '10 13:09

os x nerd


2 Answers

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.

like image 141
os x nerd Avatar answered Sep 18 '22 17:09

os x nerd


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.

like image 28
Carlton Gibson Avatar answered Sep 18 '22 17:09

Carlton Gibson