Skip to content
Tom Harrington edited this page Apr 20, 2019 · 5 revisions

mogenerator

Generates Objective-C and Swift code for your Core Data custom classes.

Use mogenerator to generate custom subclasses of NSManagedObject for entities in your model file. Generated code has two classes per entity. One is the "machine" file which is automatically regenerated as needed. The other "human" file is generated only when it doesn't already exist.

For example, for an entity named Event, the classes are:

  • _Event: Subclass of NSManagedObject. This file will be regenerated by mogenerator if the Event model has changed. Normally you would not edit this file.
  • Event: Subclass of _Event. This file is generated only if it does not exist, and is never regenerated. This is where you put custom code.

Xcode has included the ability to generate Core Data subclasses for many years, and recent versions of Xcode do so automatically. mogenerator strives to generate better, more powerful code.

Some benefits include:

  • Enumerations of attribtue and relationship names, which eliminates the need for "stringly tpyed" code.
  • Swift property types. Why use a plain NSSet when you can have a typed Set?
  • Convenience code to look up a subclass entity name and description.
  • Add custom imports to generated code, which is useful for transformable properties with custom types.
  • Create your own templates for your custom classes.
  • Support for Swift enumerations with Foundation raw value types.
  • Use a custom base class as the ancestor of your model classes.

Useful Pages

Clone this wiki locally