user7219266
user7219266

Reputation:

iOS - How to migrate 2 Entities into 1 using Core Data?

In my current model version I have this 4 Entities :

In my App I have different blocs in which I display information.

This is why I have entities RadarAnimation and SatelliteAnimation, in order to recognize those blocs by type.

Anyway, my issue is that I want to migrate 2 blocs in 1. And instead of having 4 Entities, I would like to have :

I don't need the relationships anymore.

I know I can rename an Entity in a lightweight migration process.

What I would like to do is :

Does this way of handling my issue will affect the migration process ? Can I rename and remove relationships in a new data model version ?

Upvotes: 0

Views: 44

Answers (1)

Tom Harrington
Tom Harrington

Reputation: 70936

This should be possible with automatic lightweight migration. Deleting entities and relationships just works with no extra steps, so that's fine.

To rename something you'll use the renaming identifier in the model editor. After you create the new version of your model, select the entity you want to rename in the model editor. Change its name but set the renaming identifier to the old name. In your case, change the entity name from RadarAnimation to Animation, but then also set the renaming identifier on the entity to RadarAnimation so Core Data knows what it used to be called.

Renaming identifier

Incidentally attributes and relationships can also have renaming identifiers, so they can also be renamed this way.

Apple provides detailed documentation on what can be done with lightweight migration which will probably be useful as you go through this.

Upvotes: 1

Related Questions