If you design your data model with parent entity, then you are most likely doing it wrong, unknowingly.
Because when you do so, Core Data will create 1 common table for ALL the children entities!
This is bad design (on Core Data part) and it will slow down the performance.
Read more about this under the section Entity Hierarchy vs. Class Hierarchy.
Designing a flat Entity Hierarchy
When you have common attributes (such as
updatedAt) between entities, most likely you only want to enjoy the convenient of using them in your code.
- Copy and paste the common attributes across entities
- Create a parent
NSManagedObjectthat declare the common attributes
- Subclass with the parent
When using mogenerator, the class files are auto generated, and it is generated according to the schema design.
This complicate things..
- Create the parent entity with the common attributes
- In all the
_Entity.h, subclass with the parent class instead of
NSManagedObject, and remove codes on the common attributes
objectIDin the parenty entity class (because each child has the same attribute)
Tedious workaround, but I don’t have a better way to work with mogenerator.
If you know, let me know :)