Search code examples
core-datamogenerator

CoreData: Mogenerator vs. Categories


I have recently inherited a CoreData project from an outside developer. Where I expected to find all my auto-generated NSManagedObject sub-classes, I instead have (what some googling reveals to be) classes generated by Mogenerator, a tool that I have no experience with.

I understand that the purpose of using this tool is to make it so that you can add custom code into the classes corresponding to the CoreData entities without worrying about it being lost when the model changes and the classes are regenerated... but I can do this anyways by using categories.

I currently do not see a real advantage to using Mogenerator over categories.

What are the advantages/disadvantages of using Mogenerator vs. categories? Does Mogenerator serve any additional purposes?


Solution

  • An advantage of using classes vs categories, is that you can extend functionality by subclassing and overriding.

    For instance, if your model has subentities, it is possible for them to inherit functionality from a common master class. Subclasses could define specific behavior by overriding the desired methods. On the other hand, it is possible to override methods defined in categories, but it is not recommended. This means logic implemented as categories would have to be repeated in every subclass.

    A lot of code in managed objects is boilerplate, so it's really nice to have mogenerator do it automatically.