YAML to Objective C

Generate Objective-C model classes from a YAML sample.

YAML to Objective-C – Models for legacy Apple codebases

The YAML to Objective-C converter generates model classes for iOS and macOS projects that still use Objective-C. Paste a YAML configuration or API sample and get an @interface with typed properties plus an @implementation that converts to and from NSDictionary.

How YAML maps to Objective-C

The input is parsed with the YAML 1.2 core schema; anchors and aliases are resolved and comments ignored. Mappings become classes, sequences become NSArray properties with lightweight generics, strings become NSString, and numbers and booleans become NSNumber so a missing value can be nil. Lists of mappings are merged into one class, so every item of the list uses the same model.

Generated methods

Each class gets a +fromDictionary: factory that reads the known keys, skips NSNull, and builds nested objects and arrays of objects, and a -toDictionary method that turns the model back into Foundation collections – handy for writing the data to a plist or JSON with NSJSONSerialization.

Options

Set the root class name and an optional class prefix. Property names are derived from the original YAML keys in camelCase, while the dictionary lookups keep the original key spelling, so snake_case and kebab-case keys still map correctly.

Getting a dictionary from YAML

Foundation cannot read YAML directly. Common approaches are bridging to the Swift library Yams, embedding LibYAML, or converting YAML to JSON during the build and loading the JSON with NSJSONSerialization. All of them produce an NSDictionary for fromDictionary:.

Typical uses

Bundled configuration and feature flags in older apps, test fixtures written in YAML, and gradual migrations where Objective-C and Swift share the same data files.

Validate your input with the YAML Validator, convert it with YAML to JSON, or start from JSON with JSON to Objective C.

Frequently Asked Questions

Foundation has no YAML parser, so use a library such as Yams (via a small Swift bridge) or LibYAML, or convert the file to JSON at build time. Any of these produce an NSDictionary you can pass to fromDictionary:.

Objective-C has no namespaces, so a two- or three-letter prefix such as ABC avoids clashes with Apple frameworks and third-party libraries. Leave it empty if your project does not use one.

Scalars are exposed as NSNumber properties, which can hold integers, doubles and booleans and can be nil when a key is missing. Use integerValue, doubleValue or boolValue to read them.

No. The conversion runs entirely in your browser.