views:

273

answers:

5

I would like to write some Objective-C code for distribution. What is the best way to package up the output. In Java you can package up your code in a JAR file and distribute that. What would be the equivalent in Objective-C?

The following link is close, but seems to address more of the namespace issues which I am not concerned about. I am mostly concerned about setting the code up for easy distribution.

http://stackoverflow.com/questions/1000707/objective-c-equivalent-of-java-packages

+4  A: 

You want to create a Framework. There is a starting point in Xcode for a new project to create one of these. There are a few caveats and gotchas, but on the whole the process is straightforward.

Edit: For clarification: If you are planning to distribute it as FOSS; packing it up in a framework might be overkill; just distributing the source code might be a more sensible and simpler option. But if you would like to keep the source to yourself or distribute it with a collection of relevant resources, a framework might definitely be a good idea.

Reedit: For an introduction, see http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/

Williham Totland
Do you know of any good reference points to start from?
banno
+1  A: 

You didn't say if it was for iPhone or not. On the iPhone, it needs to be a .sa (statically linked library) -- but I think the normal distribution would by a .dylib or .so

Lou Franco
It would, quite actually, be a .framework; which is a .dylib packed in a folder hierarchy with relevant header files and resources.
Williham Totland
Primarily iphone - but I may want to make it generic enough to work on the Mac too.
banno
A: 

Java programs run in the context of a virtual machine. Jar contains abstract bytecodes which must be converted into native machine code by the VM.

Objective-C, like C, is compiled into native machine code, such as a Win .exe file, directly runnable by the operating system.

Most programs of any complexity consist of more than a single file and include DLLs, icon files, etc. The configuration of your files for distribution would usually be handled by a setup utility.

Buggieboy
The last part of this seems totally unrelated to Objective-C. There is no "setup utility", and thankfully, no DLL's in the same sense as Windows. Dynamic libraries on OS X can actually contain multiple versions, so clients can specifically link against a given version and not break if the library must violate backwards compatibility. Frameworks are the way to go.
Quinn Taylor
Objective-C is not exclusive to OS X.
Buggieboy
+5  A: 

A framework is almost certainly the way to go. One of the really nice things about Frameworks on OS X is that they can bundle the executable code, headers, metadata, images, icons, etc. in a single package. Further, frameworks can be included in */Library/Frameworks/ or even inside your app bundle to completely decouple from any other app's dependency on a given version of the framework.

Apple's Framework Programming Guide is the best place to get started with frameworks.

Creating a framework is simple. Basically, in Xcode you choose File > New Project... and select Framework, then Cocoa Framework. This will set up a new project with framework target and automatically package everything up for you when you build.

Don't forget that documentation and unit tests are a Good Thing™, especially for frameworks, which are inherently more likely to be used by multiple clients than most end-user code. You can add more targets to your framework Xcode project to document and test it.

Since you're looking for examples, check out CHDataStructures.framework (a project which I develop) and PSMTabBarControl.framework (which includes lots of extra resources in the framework). Both are open-source, and should provide adequate examples for rolling your own.

One word of advice to save you some head-scratching: your header files will not be copied to the built framework unless you click on the framework target and change the Role to "Public" (or "Private").

Quinn Taylor
A: 

You could compile it as a Framework or as a static library (.so I believe).

Jason