Is there a native YAML library for iPhone?

2019-01-31 12:28发布

问题:

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

回答1:

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.



回答2:

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.



回答3:

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];


回答4:

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



回答5:

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)


回答6:

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.



回答7:

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.