I want to know whats best practice when dealing with executing custom code after Core Data lightweight migration
.
I'll try to explain what I mean, suppose I have 3 versions of my app:
ver 1.0.0 (core data model version is 1.0)
ver 1.1.0 (core data model version is 1.0)
ver 2.0.0 (core data model version is 2.0)
As you can see the core data model didn't changed between version 1.0.0 and 1.1.0, but it did changed between 1.1.0 and 2.0.0.
Now in addition to the model changes I need to run some custom code that updates some existing entities.
This custom code need to be executed if user just installed a newer version with with different model version, for example:
if user has version 1.0.0 and he is now installing version 2.0.0 - the code should be executed
if user has version 1.1.0 and he is now installing version 2.0.0 - the code should be executed
but on the other hand I dont want to run this code if the user installed a new version with same model version, or if user didn't have the app before, so there is no old data to update.
for example:
if user has version 1.0.0 and he is now installing version 1.1.0 - the code should NOT be executed
if user doesn't have the app and he is now installing version 2.0.0 - the code should NOT be executed
I search for this issue and found some questions talking about it:
Detecting a Lightweight Core Data Migration
Core Data : Post migration, additional migration code
but didn't find the right way for doing exactly what I wanted,
any help will be appreciated