I have been doing iPhone/iOS development for some time now. But with the new kid on then block, the Mac App Store, I have returned to doing some native Mac programming again. I got to update an old Mac app for the Mac App Store too, Mye. When I’m at it I also got into supporting a great opensource project started by Rasmus Andersson named kod
. kod
is an editor specifically for programmers.
This weekend I started to look into how to bundle frameworks. Working on kod
made me think of making an own little program to collect and organize snippets, thoughts and numbers. And I got a little sidetracked when my thoughts drifted into frameworks.
How should bundled frameworks actually be built and used, or at least used easily?
I looked around Xcode to see if I could find any direct clues of it. No, not obvious enough for me. The documentation has a pretty high threshold to grasp, even if it’s usually are very thorough. But, I’m beginning to feel comfortable searching and reading it now. Think I figured it out.
Lets take the steps one by one.
- Create a Cocoa Framework project
- Open the info for the target. Type
install
in the search field. Make sure All Configurations is selected - Enter
@executable_path/../Frameworks
in the Installation Directory - Add some source code to the project
- Select the target and change the Role for the headers that should be copied into the framework, the ones that should be imported later when the framework is used. Change from project to public
- Build (build Release to get all architectures built into the framework)
You should now have a framework that can be bundled internally with an app.
So, how should it be used?
Lets take the steps one by one.
- Create a Cocoa Application project
- Drag the framework from the Products group in the frameworks project to the Frameworks group in the new app project. Copy or reference it if you like
- Add some code that uses the framework
- Select the target and Add » New Build Phase » New Copy Files Build Phase. Select Frameworks as Destination
- Drag the framework from the Frameworks group to the new build phase (should be the last build phase under the target)
- Build and run. You should now have created an app that have the framework bundled.
That should be it.
It’s also possible to make the app project dependent of the framework project and you can hook the pieces up to handle building of it at the same time as the app builds. But I leave that as an exercise for you.
If you would like to get two example projects to have a look see at grab a zip here .
By Edward Patel, 27 Jan 2011Tweet
Show comments