7

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.

Objective-C equivalent of Java packages?

Community
  • 1
  • 1
banno
  • 1,529
  • 8
  • 12

5 Answers5

7

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").

Community
  • 1
  • 1
Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
  • I down ticked this because the links provided are, more or less, broken. CHDataStructures.framework WebSVN contains nothing and PSMTabBarControl.framework result in 404. – Frank C. Jan 09 '11 at 11:18
5

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
  • 28,471
  • 6
  • 52
  • 68
1

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
  • 87,846
  • 14
  • 132
  • 192
0

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

Jason
  • 452
  • 4
  • 9
-1

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
  • 4,636
  • 4
  • 55
  • 79
  • 1
    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 Jul 13 '09 at 17:32
  • Objective-C is not exclusive to OS X. – Buggieboy Sep 30 '09 at 14:10