About the XML to Objective-C Converter
Objective-C property declarations carry more detail than most languages: as well as the type you have to state the memory semantics, and getting that wrong causes either a leak or a crash. This generator applies the conventions automatically. Strings are declared copy, which protects against a mutable string being handed in and changed underneath you. Object references and collections are strong. Scalars such as NSInteger, double and BOOL are assign, since there is nothing to retain.
Collections are declared with lightweight generics, so a repeated element becomes NSArray<Departure *> * rather than a bare NSArray, giving you compile time checking and better completion. Nested elements each produce their own interface, and a forward @class declaration is emitted at the top when there is more than one type, so the order of the interfaces in the file never matters.
Property names that clash with Objective-C keywords or with methods already on NSObject are renamed with a Value suffix, because a property literally called description would override the debugging method that every object inherits. Add a class prefix in the toolbar to follow the two or three letter convention that keeps class names unique in a language without namespaces. Keep the implementation stubs to get a compilable pair of blocks, or turn them off for a header only file. For Swift projects, JSON to Swift is a better starting point.
How to use
- Paste an XML sample containing the fields you want as properties.
- Type a class prefix such as
MYto keep the generated class names unique. - Leave the implementation stubs on for a file that compiles as it stands.
- Copy the interfaces into your header, or download the
.hfile.
Common questions
- Why did a property named description get renamed?
- NSObject already defines description, so a property with that name would override it. Reserved names gain a Value suffix to stay safe.
- Why are strings declared copy rather than strong?
- A caller can pass an NSMutableString and mutate it later. Copying on assignment keeps your object stable.
- Does it write parsing code?
- No. It declares the model. Fill the properties with NSXMLParser or a third party parser of your choice.
- Is ARC assumed?
- Yes. The property attributes shown are the ARC ones, which is the default for any project created in the last decade.