26

I'm considering using YAML as part of my next iPhone application, but I haven't been able to find an Objective-C library to use.

The Wikipedia page for YAML mentions one, but the link is dead.

Is there an Objective-C library that can parse YAML into native collection objects (NSArray, NSDictionary, etc...)?

Ben S
  • 68,394
  • 30
  • 171
  • 212

7 Answers7

6

The Cocoa extensions for Syck are probably what you're looking for -- it's where the library that Shaggy Frog mentioned seems to be living these days.

John Biesnecker
  • 3,782
  • 2
  • 34
  • 43
6

You can try YAML.framework it's LibYAML based, it's fast and easy to use. Follows the same pattern as standard NSPropertyListSerialization.

You can use it for iOS (iPhone/iPad) development.

Mirek Rusin
  • 18,820
  • 3
  • 43
  • 36
  • Hi, I tried yaml.framework, and had problems with serialisation: It uses UTF16 even though it attempts to set utf8. I've since had more luck with yamlkit. – Chris Feb 15 '12 at 11:15
5

The YAMLKit framework is a thin wrapper around LibYAML. It does exactly what you want. For example:

[[YKParser alloc] init];
[p readString:@"- foo\n- bar\n- baz"];
id result = [p parse];
/* result is now an NSArray containing an NSArray with elements:
   @"foo", @"bar", @"baz" */
[p release];
sebnow
  • 1,380
  • 12
  • 11
  • 2
    YAMLKit doesn't include libyaml, so you need to grab that yourself. This approach is a bit cleaner, but also a bit more troublesome. – febeling May 02 '12 at 11:17
3

I recently wrote modern ObjC-YAML bindings, based on the standard NSCoder/NSKeyedArchiver interface: http://github.com/th-in-gs/YACYAML. I'm using them in my own projects, and intend to maintain them for at least as long as I continue to do so.

More here: http://www.blog.montgomerie.net/yacyaml

th_in_gs
  • 539
  • 4
  • 15
1

IF you are doing alot of c++ in your iPhone projects, then please have a look at yaml-cpp:

http://code.google.com/p/yaml-cpp/

  1. has native iPhone support (via it's cmake build system)
  2. has no dependencies beyond a good compiler and cmake
  3. is very c++ friendly (thus, the name) with solid documentation (see the wiki/HowToParseADocument page)
vizionary
  • 106
  • 2
0

I found this right from YAML's front page. But it looks like it might be out of date (c. 2004?), and the CVS link doesn't work for me.

I would bet that it's just a thin wrapper around an underlying C library like this or this... C code being "native" code that the Objective-C compiler will grok.

Shaggy Frog
  • 27,575
  • 16
  • 91
  • 128
  • Yeah, that's essentially what I'd like. I know I could just use the C or C++ YAML parsers, but I would really like to have the wrapper around it that returns the right collections and NSStrings rather than char* – Ben S Dec 15 '09 at 19:11
  • I hear what you're saying. Unfortunately, it looks like there's no one making that wrapper anymore. I'd follow up with their mailing list directly... maybe someone's got one tucked away that they haven't released yet. – Shaggy Frog Dec 15 '09 at 19:35
-1

I found this question looking for YAML + objective C options. I ended up using this solution: https://github.com/icanzilb/JSONModel. Very cool, up to date and easy to use. Parses yaml directly into objective C models that you create inheriting the JSONModel class.

santuxus
  • 3,662
  • 1
  • 29
  • 35