{ Hi! I'm Mike }
I'm a core developer with The Horde Project and a founding parter of Horde LLC - the company behind the world's most flexible groupware platform. This is my personal blog full of random thoughts about development and life in general.
November 25, 2008

The Cocoa Diaries Part I

I've been slowly plugging away at a new iPhoto export plugin for exporting photos to an Ansel server.  This was really my first Cocoa project and my first C related project in quite a number of years.

 I found picking up the basics of objective C  not that difficult, but I was stumped trying to do something that should have been fairly easy.  For this plugin, I am using the Cocoa XML-RPC Framework to manage (surprisingly enough) a xml-rpc connection to the Horde server.  During development, I just had it linked against the framework in my Library/Frameworks directory - which obviously won't work on someone else's machine.  So, time to move the framework into the bundle for the plugin.

I decided I wanted to include the source for the framework in the same project as the plugin. This makes debugging easier and also makes distributed development with other developers easier.  Sure, no problem,  just add the source, add a new framework target, copy files etc... but no dice.  For the life of me, I could not figure out why this would not work. Googled, hacked, googled some more.  Then it hits me - this is a plugin, not a standalone application.  When setting the Installation Path build property for the framework target in Xcode, I was using @application_path and not @loader_path. Duh. 

So, seeing how that particular problem cost me so much time, I thought I'd document this in the hopes it will help someone else avoid the same mistake. Here are the steps required to add the source code for a framework into an existing Xcode project for a plugin. (These are all basically the same steps as an adding it to an application, except for the setting of the Installaion Directory property).

  • Import the framework's source tree using the Import Existing Files command
  • Create a new target for the framework. Obviously, this should be a Cocoa Framework target.
  • Open the Build tab of the Inspector for the framework target, and set the Installation Directory property of the target to be: @loader_path/../Frameworks
  • Open the target for the plugin so you can see the build phases - drag your framework product (not the target) to the Link Binary with Libraries build phase.
  • Add a new Copy Files build phase and drag your framework product to the it. Open an inspector and set the Destination of the build phase to Frameworks.
  • Select the application target, open an inspector and add your framework as a dependency. This will assure that the framework is built before the plugin so that it's available to link against.  This allows you to keep the target of the Xcode project set to your plugin.

Yep, probably all simple stuff for an experienced x coder, and it actually is mostly pretty simple stuff...except for the fact that I forgot that I could not use @application_path as the Installation Directory.