Core Data Performance with Single Parent Entity

I worked with @deathbob on this project as the iOS lead. In our instance I had multiple classes which contained the attributes “remote_id” and “remote_update”. I initially set the tables up using subclasses. I had a “RemoteEntity” abstract entity which contained those attributes and a bunch of other entities which inherited from it, each with their own. I thought that we would end up with a bunch of tables each with remote_id, remote_update, and then their custom attributes. Instead we ended up with the massive table you describe.

The fix was pretty simple you must not set up inheritance through the GUI. Instead include all attributes for that object including your shared ones in the Core Data modeller (this means “remote_id” and “remote_update” will appear in each entity. That being said we can still use a subclass. After generating your models’ classes, create the parent entity’s class. This must not be in the GUI. It should inherit from NSManagedObject and in the .m file the properties should use @dynamic instead of @synthesize. Now that you have the parent class it is time to adjust the child classes. Set the parent class to RemoteEntity (in my example) instead of NSManagedObject. Then remove any properties that appear in your super class (in my example, “remote_id” and “remote_update”).

Here is an example of my super class https://gist.github.com/1121689.

I hope this helps, hat tip to @deathbob for pointing this out.

Leave a Comment