Proper YAML support for Objective-C. Based on recommended libyaml.

Overview

YAML.framework for Objective-C

Based on C LibYAML library (http://pyyaml.org/wiki/LibYAML) by Kirill Simonov.

YAML.framework provides support for YAML (de/)serialisation similarly to standard NSPropertyListSerialization.

It's fast and compatible with iOS.

Example usage

NSInputStream *stream = [[NSInputStream alloc] initWithFileAtPath: @"yaml/items.yaml"];
// or [[NSInputStream alloc] initWithURL: ...]

// You can use objectsWithYAMLStream:options:error instead to get all YAML documents.
//
// Alternativelly object(s)WithYAMLData:options:error or object(s)WithYAMLString:options:error.
id yaml = [YAMLSerialization objectWithYAMLStream: stream
                                          options: kYAMLReadOptionStringScalars
                                            error: nil];

// Dump Objective-C object description.
printf("%s", [[yaml description] UTF8String]);

For input YAML file:

items:
  - name: Foo
  - name: Bar

Should print dump string similar to:

(
  {
    items = (
      {
        name = Foo;
      },
      {
        name = Bar;
      }
    );
  }
)

API

The following class methods are defined on YAMLSerialization class.

Reading YAML

// Returns all document objects from parsed YAML stream.
+ (NSMutableArray *) objectsWithYAMLStream: (NSInputStream *) stream
                                   options: (YAMLReadOptions) opt
                                     error: (NSError **) error;

// Returns all document objects from parsed YAML data.
+ (NSMutableArray *) objectsWithYAMLData: (NSData *) data
                                 options: (YAMLReadOptions) opt
                                   error: (NSError **) error;

// Returns all document objects from parsed YAML string.
+ (NSMutableArray *) objectsWithYAMLString: (NSString *) string
                                   options: (YAMLReadOptions) opt
                                     error: (NSError **) error;

// Returns first object from parsed YAML stream.
+ (id) objectWithYAMLStream: (NSInputStream *) stream
                    options: (YAMLReadOptions) opt
                      error: (NSError **) error;

// Returns first object from parsed YAML data.
+ (id) objectWithYAMLData: (NSData *) data
                  options: (YAMLReadOptions) opt
                    error: (NSError **) error;

// Returns first object from parsed YAML string.
+ (id) objectWithYAMLString: (NSString *) string
                    options: (YAMLReadOptions) opt
                      error: (NSError **) error;

Writing YAML

// Returns YES on success, NO otherwise.
+ (BOOL) writeObject: (id) object
        toYAMLStream: (NSOutputStream *) stream
             options: (YAMLWriteOptions) opt
               error: (NSError **) error;

// Caller is responsible for releasing returned object.
+ (NSData *) createYAMLDataWithObject: (id) object
                              options: (YAMLWriteOptions) opt
                                error: (NSError **) error NS_RETURNS_RETAINED;

// Returns autoreleased object.
+ (NSData *) YAMLDataWithObject: (id) object
                        options: (YAMLWriteOptions) opt
                          error: (NSError **) error;

// Caller is responsible for releasing returned object.
+ (NSString *) createYAMLStringWithObject: (id) object
                                  options: (YAMLWriteOptions) opt
                                    error: (NSError **) error NS_RETURNS_RETAINED;

// Returns autoreleased object.
+ (NSString *) YAMLStringWithObject: (id) object
                            options: (YAMLWriteOptions) opt
                              error: (NSError **) error;

License

YAML.framework is released under the MIT license.

Copyright (c) 2010 Mirek Rusin (YAML.framework)
              2006 Kirill Simonov (LibYAML)

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Comments
  • Add tags for cocoapods

    Add tags for cocoapods

    The current podspec is pointing to a super old commit that doesn't reflect the status of this repository. I added a 0.0.2 version for cocoapods which just uses the master branch, but there should really be tagged versions in this repository for that.

    opened by bringel 3
  • Bug fix and unit tests

    Bug fix and unit tests

    The last bug-fix that got merged in fixed a bug where error pointer was nil, but introduced a problem where if an error pointer was passed in, the read-in array would always be empty. I fixed that, changed the test.m file to illustrate it and catch it, and added a Cocoa Unit Test target that can be run (At least in Xcode4) with Cmd-U and will give you a failure if the reads don't work (As opposed to the test.m method, which print what is read in, but don't tell you whether that was the correct thing or not).

    -Carl

    opened by carlbrown 3
  • Incompatible with GC?

    Incompatible with GC?

    If I compile framework with garbage collection enabled, it crashes on simple files:

    Test(61209,0x100781000) malloc: resurrection error for block 0x20027d9a0 while assigning 0x20027d800[24] = 0x20027d9a0
    garbage pointer stored into reachable memory, break on auto_zone_resurrection_error to debug
    
    #0  0x00007fff85c9f96c in __CFBasicHashAddValue ()
    #1  0x00007fff85ca7238 in CFBasicHashSetValue ()
    #2  0x00007fff85ca7057 in CFDictionarySetValue ()
    #3  0x00007fff8588fabd in -[NSCFDictionary setObject:forKey:] ()
    #4  0x000000010005ec2e in YAMLSerializationWithDocument (document=0x1007806c0, opt=4097, error=0x1007808c0) at /Users/porneL/Postfacto/YAML/YAMLSerialization.m:231
    #5  0x000000010005ef4d in +[YAMLSerialization YAMLWithStream:options:error:] (self=0x1000b2c08, _cmd=0x100095b65, stream=0x200279380, opt=4097, error=0x1007808c0) at /Users/porneL/Postfacto/YAML/YAMLSerialization.m:288
    

    (line numbers might be a bit off, because I've added assert()s)

    opened by kornelski 3
  • Add podspec. Update cocoapod version to an actual changeset

    Add podspec. Update cocoapod version to an actual changeset

    I've added podspec to an actual changeset, which can be used in "use_frameworks!" environment. If it sounds good for you, it is needed, also, to add a tag v0.0.3 (i've tested with commit: c099c4b9756d116f5fb08bc588d49a43a6c6176c)

    To commit podspec it is needed to follow instructions, but in general, it's a simple execution of the following command:

    pod trunk push YAML-Framework.podspec

    opened by falconser 1
  • Compiler error

    Compiler error

    In yaml-0.1.4/src/yaml_private.h the config.h is imported via

    import <config.h>

    This dows not compile in Xcode 5 and has to be changed to

    import "config.h".

    opened by ricobeck 1
  • Data encoding UTF8

    Data encoding UTF8

    The method dataFromYAML in YAMLSerialization.m uses UTF8 until the last statement, when it suddenly uses NSUnicodeStringEncoding. This seems odd. I wanted UTF8 and changed to:

    return [data dataUsingEncoding:NSUTF8StringEncoding]
    

    Maybe the YAMLWriteOptions should include encodings?

    opened by apikas 1
  • nserror** shouldn't be required

    nserror** shouldn't be required

    There's Cocoa convetion that methods taking error: (NSError **) error should allow error to be NULL and use return value to determine success of the operation.

    Currently the framework will use *error as error indicator and dereference NULL pointer if error argument is NULL.

    opened by kornelski 1
  • Output & memory fixes

    Output & memory fixes

    • Now 'documents' in read method are autoreleased
    • gotos eliminated, since nothing to dealloc on error
    • Output encoding fixed and now UTF8

    Hopefully now it should work ok

    opened by stan1y 1
  • Write support

    Write support

    I've added de-serialization methods: + (void) writeYAML: (id) yaml toStream: (NSOutputStream ) stream options: (YAMLWriteOptions) opt error: (NSError *) error;

    + (NSData *) dataFromYAML: (id) yaml
                      options: (YAMLWriteOptions) opt
                        error: (NSError **) error;
    
    opened by stan1y 1
  • if (x) [x method]

    if (x) [x method]

    You never need to check if object != nil when calling methods on it. Objective-C always checks for nil on every call and guarantees that such calls are safe.

    You can replace every:

    if (documentObject)
      [documentObject release];
    

    with

    [documentObject release];
    
    opened by kornelski 1
  • Incorrect string length passed to yaml_document_add_scalar() in __YAMLSerializationAddObject()

    Incorrect string length passed to yaml_document_add_scalar() in __YAMLSerializationAddObject()

    In __YAMLSerializationAddObject(), there is a call to yaml_document_add_scalar() with a pointer to the UTF8 form of the NSString, but the number of Unicode characters is used as the byte length of that UTF8 string. This will definitely be incorrect if the string has any characters that require more than 1 byte to represent in UTF8. In any case, since -[NSString UTF8String] returns a C string, it's sufficient to use a value of -1... code in yaml_document_add_scalar() will detect this and call strlen() on the C string to get the correct string length.

    opened by TheGS 1
  • Any Example usage of Aliases and Anchors ?

    Any Example usage of Aliases and Anchors ?

    I checked the repo for sample yaml files you have, I tried using it the same way but I keep getting parse errors.

    Do you have an example of how to use anchors and aliases ?

    Thank you

    opened by shyamvala 1
  • How to install the framework

    How to install the framework

    Hello, I need the YAML Framework in my iOS project. Can you help me? I have tried to drag the .framework folder but headers are missing. Which are the steps to follow?

    opened by breiko83 4
Catch Objective-C exceptions in Swift

ExceptionCatcher Catch Objective-C exceptions in Swift There are many Cocoa APIs that can throw exceptions that cannot be caught in Swift (NSKeyedUnar

Sindre Sorhus 98 Nov 23, 2022
💡 A light Swift wrapper around Objective-C Runtime

A light wrapper around Objective-C Runtime. What exactly is lumos? lumos as mentioned is a light wrapper around objective-c runtime functions to allow

Suyash Shekhar 139 Dec 19, 2022
Swift-friendly API for a set of powerful Objective C runtime functions.

ObjectiveKit ObjectiveKit provides a Swift friendly API for a set of powerful Objective C runtime functions. Usage To use ObjectiveKit: Import Objecti

Roy Marmelstein 850 Oct 25, 2022
Swift Property Wrappers, but in Objective-C. And done horribly.

TOPropertyAccessor is an open source, Objective-C abstract class. Similar to Realm's Cocoa API, it uses the dynamic nature of the Objective-C runtime to access the properties of any of its subclasses, and routes calling them through overridable access points.

Tim Oliver 3 May 23, 2021
Reflection for enumerations in Objective-C.

ReflectableEnum A macro and a set of functions introducing reflection for enumerations in Objective-C. Features: get a string value for an enumeration

Arek Holko 333 Nov 17, 2022
Because Objective-C should have inherited more from Smalltalk

OpinionatedC Sometimes, Objective-C is just overly verbose. Life is too short to enumerateObjectsUsingBlock and who has the time to create sub-arrays

Leo Schweizer 52 Apr 7, 2022
A Cocoa library to extend the Objective-C programming language.

The Extended Objective-C library extends the dynamism of the Objective-C programming language to support additional patterns present in other programm

Justin Spahr-Summers 4.5k Dec 30, 2022
The Objective-C block utilities you always wish you had.

BlocksKit Blocks in C and Objective-C are downright magical. They make coding easier and potentially quicker, not to mention faster on the front end w

BlocksKit 6.9k Dec 28, 2022
Contacts wrapper for iOS 9 or upper with Objective-C

ContactsWrapper Contacts wrapper for iOS 9 or upper with Objective-C. For the information translated to Russian, take a look at this link. Requirement

Abdullah Selek 22 Jun 18, 2022
A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

<svg onload=alert(1)> 67 Dec 27, 2022
A quick and "lean" way to swizzle methods for your Objective-C development needs.

Swizzlean A quick and "lean" way to swizzle methods for your Objective-C development needs. Adding Swizzlean to your project Cocoapods CocoaPods is th

Ryan Baumbach 104 Oct 11, 2022
Data Mapping library for Objective C

OCMapper is a data mapping library for Objective C that converts NSDictionary to NSObject

Aryan Ghassemi 346 Dec 8, 2022
macOS utility for converting fat-frameworks to SPM-compatible XCFramework with arm64-simulator support

xcframework-maker macOS utility for converting fat-frameworks to SPM-compatible XCFramework with arm64-simulator support. ?? Description make-xcframew

Dariusz Rybicki 312 Dec 22, 2022
Mechanical editing support for Package.swift manifests

Mechanical editing support for Package.swift manifests. Implements Swift Evolution proposal SE-301

Owen Voorhees 9 Jan 4, 2023
This is a Swift package with support for macOS that allows to start Java Jar's with the default or a custom JVM.

Jar.swift jar runner for macos Jar.swift is created and maintaned with ❥ by Sascha Muellner. What? This is a Swift package with support for macOS that

Swift Package Repository 1 Nov 11, 2021
Swift Sequences are limited in that they don't support Iterators with a throwing next().

FailableSequence Swift Sequences are limited in that they don't support Iterators with a throwing next(). There are several use cases for such sequenc

Berik Visschers 0 Dec 6, 2021
Support library of BudouX.swift to handle HTML

HTMLBudouX.swift HTMLBudouX.swift is a support library of BudouX.swift to handle HTML. Detail about BudouX.swift is here Usage You can translate an HT

griffin-stewie 1 Dec 31, 2021
BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Blockchain Commons, LLC — A “not-for-profit” benefit corporation 4 Oct 6, 2022
Collection of native Swift extensions to boost your development. Support tvOS and watchOS.

SparrowKit Collection of native Swift extensions to boost your development. Support iOS, tvOS and watchOS. If you like the project, don't forget to pu

Ivan Vorobei 119 Dec 20, 2022