I'm a Rails programmer by day, but recently I've been an iPhone programmer by night. I'm working on an app that reads in data via files transferred over http. Since the Foundation API includes support for reading a property file (in XML format) into an NSdictionary, I probably should have formatted my data as XML. However, as a grizzled Rails programmer set in my ways, the thought of all the angle brackets and closing tags and weird XML editors was too much to bear. I instinctively went to the google search bar and typed in "cocoa yaml", hoping against hope for something to come up.
Something did. The YAML Cocoa parser is an excellent Cocoa framework for reading (and writing) YAML in a Cocoa app.
Having found a framework that did what I wanted, I had to somehow make it work on the iPhone, which turned to be a challenge for one main reason. Apple does not let you load dynamicly linked libraries in iPhone apps. You have to either use a static library, or just straight-up compile the code into your project. I chose the latter option, but if you would like to create a static lib for use on the iPhone,
here's how.
So in order to get this code to work on the iPhone, I had to make a few changes to make it compile. YAML Cocoa (in its pure form) allows both reading AND writing of YAML. The writing part is a bit problematic, as it depends on various methods available only in AppKit (and not UIKit). Given that I was only interested in reading YAML, my solution was simply to remove all of the code that depended upon AppKit.
So the steps are:
- Copy all of the framework .m and .h files into your iPhone Classes directory.
- Remove any code that depends on AppKit.
- Install syck (I used macports to do this).
- Ensure that the syck library and header file is in your project's library and header paths.
- Build.