0

Recently, I am trying to refine my code. I found that all my entities has attributes named identifier and owner, so I want to create a entity to be their parent which contains identifier and owner.

enter image description here

Following is the result, all object inherit from a parent named SRModel, which has identifier and owner attributes.

enter image description here

However, after I delete all these redundant properties, the persistent store is not able to auto migration. How can I solve the problem? Do I have to do migration by myself? Are there any simple way to do so?

Hubert Wang
  • 502
  • 5
  • 17

1 Answers1

0

According to Apple's Core Data Model Versioning and Data Migration Programming Guide, you can't do that automatically.

You cannot, however, merge entity hierarchies; if two existing entities do not share a common parent in the source, they cannot share a common parent in the destination

Note Andy Riordan's point about inheritance. And don't just take his word for it; look at the generated .SQLite files yourself under the old and new models. Adding a parent entity with only two common attributes will just make your entities, and backing tables, larger, with no performance benefit. If you really want to note the two common elements, use a Protocol to call them out.

Hal Mueller
  • 7,019
  • 2
  • 24
  • 42