Wednesday, December 2, 2015 [Tweets] [Favorites]

Generating Core Data Swift

Human Friendly:

There are two [Xcode] generation options, with “Use scalar properties for primitive data types” you get usefully typed integers, floats, doubles and bools but lose the expression to express optionals/nil values. This is presumably due to the limitations of the Objective-C based API. It also expresses date types as NSTimeIntervals (Doubles) rather than NSDates. The other option will generate with objects so you will get NSDates but for number values and Booleans you will get NSNumbers which lose information about whether it is a floating point type, integer or boolean.

[…]

The Core Data model file is actually a very simple XML file and parsing it is relatively straightforward. I’ve written a quick (but brittle so far) parser using NSXMLParser. This means that I can easily get at the key information (Entities, Attributes and the relationships) to generate the code I need.

See also: mogenerator.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment