YAML to Objective C Converter

Generate Objective-C interfaces from a YAML file, with property attributes chosen to match each inferred type.

YAML
Objective-C
Runs locally in your browser

About the YAML to Objective C Converter

Older iOS and macOS codebases often keep their fixtures and seed data in YAML because it is easier to review than a plist, then need a model class to load it into. Writing those interfaces by hand is slow and the property attributes are easy to get wrong, so this page derives them from the file.

Each mapping in the YAML becomes an @interface block. Scalar values are declared as NSInteger, double or BOOL with assign, strings as NSString * with copy, and nested mappings as object pointers with strong. A sequence of mappings becomes an NSArray with a lightweight generic parameter naming the item class, which gives the compiler something to check and Xcode something to complete.

Keys are converted to camel case property names, and any that collide with a keyword or with an inherited NSObject method are given a Value suffix so they cannot shadow something important. A class prefix is worth setting, since Objective-C has no namespaces and a class called Site in an app of any size will collide with something eventually. Note that YAML booleans are the words true and false, so a value written as yes is a string and is typed as one. For the same starting point in a mixed project, XML to Objective-C reads XML instead.

How to use

  1. Paste the YAML file that holds your fixture or configuration.
  2. Set a class prefix of two or three letters to keep the class names unique.
  3. Name the root class, since a YAML document has no element name to borrow.
  4. Copy the interfaces into a header file, or download the .h file.

Common questions

Why is a key written as yes typed as a string?
The YAML 1.2 core schema treats only true and false as booleans, so yes and no stay text and are typed accordingly.
Are the property attributes right for ARC?
Yes. Copy for strings, strong for objects and collections, assign for scalars, which is the standard ARC set.
Do I get initialisers as well?
No. The output declares properties. Add your own designated initialiser or set the properties after allocation.
What if two mappings have different keys under the same name?
They become separate numbered classes rather than being merged, so no field is quietly lost.