How many migration steps does Core Data lightweight migration have?

拈花ヽ惹草 提交于 2019-12-13 12:31:58

问题


I use Core Data and lightweight migration for my iPhone app.

Suppose I have created 3 versions of the data model for the app. One user installed the early version of my app and its data model version is still v1. When the user update the app to the latest version which has the data model version v1,v2 and v3, what happened during the update?

The sqlite database migrate from v1 to v2 first and then migrate from v2 to v3? Or it just jump from v1 to v3?


回答1:


Internally, I believe Core Data lightweight migration will apply the changes to each subsequent version in order, but for your purposes you can think of it as a migration that happens directly to the final version. To my knowledge there are no "hooks" to intercept and run code between versions during a lightweight migration.

If you need to alter data or add new data, you should determine the model version dynamically and react accordingly.




回答2:


Core Data doesn't care about the order of versions and it doesn't care about any intermediate versions. It just knows the source version and target version, it will migrate directly between these.

Generally with lightweight migrations this will work fine though.



来源:https://stackoverflow.com/questions/19592423/how-many-migration-steps-does-core-data-lightweight-migration-have

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!