1
votes

Can I do the following?

  1. Start with v1.0 of an app. Version data model, designate new version as active schema
  2. Set correct options in appDelegate for creating NSPersistentStoreCoordinator using lightweight migration
  3. Make simple changes to the model and update classes. Compile and verify that everything works.
  4. Make another change to the data model without changing the version, and again update the classes

Of course when I run, the data model will be incompatible since I have changed it without versioning. But since I will not be shipping the intermediate version, my suspicion is that the data migration should work fine when updating from v1.0 to the double-updated data model.

Is this accurate?

1

1 Answers

1
votes

It will work as long as the following are true:

  1. You have created a new model version for each of these steps; so in your example above you should have three at the end: original, intermediate, final.
  2. The app must be able to do a lightweight migration from 1 to 3. If it cannot it will not go through 2 if the data on disk is still in the structure of 1.

If all of that is true then it will work. And you can even go so far as to not ship v2 in the final build (although they are small and it is usually not worth the effort).

During development my recommendation is to always keep the v1 data around, only change v2 and remigrate every time you need to adjust v2. Then there is no intermediate to deal with. However that is not always possible when dealing/working with beta testers.