Arsen
Arsen

Reputation: 10951

CoreData migrations without versioning

Right now I use versioning to make any changes in a database. But it brings some problems. For example it's hard to merge a feature branch with a new db version into a master/dev where somebody also added a new version.

So my question: Is it safe to change db in a single xcdatamodel without adding new versions? I tried so and it works but everywhere on the internet I see warnings that you must not do that.

iOS9+.

I found this: https://stackoverflow.com/a/37264096/5328417 but it's without a proof

Upvotes: 11

Views: 766

Answers (2)

Viktor Kucera
Viktor Kucera

Reputation: 6335

As @pbasdf noted, since iOS 9 you can do a lightweight migration without adding any new model version. Source model (previous model version) is cached to store and used as a last ditch effort during lightweight migration.

I am using this feature in my own apps successfully. Although I was not able to find this documented. Just that WWDC video (18'15 Model Caching) mentioned. This is exactly the reason why Core Data is so mysterious sometimes..

Upvotes: 10

Oleg
Oleg

Reputation: 518

If your app is in development stage then you may use one model without versioning.

But if it is release on the App Store then you have to create the versions when you make changes (such as adding a new attribute, adding a new entity, renames attributes etc.). Otherwise, Core Data won't perform lightweight migration.

Upvotes: 0

Related Questions