Database Reference
In-Depth Information
Finally, call migrateStoreAt(URL:fromModel:toModel:mappingModel:) ,
which you wrote at the start of this section.
Note that if you're starting from version 1 or 2, there's a recursive call to
performMigration() at the end. That will trigger another run to continue the
sequence; once you're at version 3 and run the migration to get to version 4, there
is no more recursive call. You can imagine adding to this method as you add more
data model versions to continue the automatic sequence of migrations.
Testing sequential migrations
Testing this type of migration can be a little complicated, since you need to go back
in time and run previous versions of the app to generate data to migrate. If you
saved copies of the app project along the way, then great! Otherwise, you'll find
previous versions of the project in the resources bundled with the topic.
First, make sure you make a copy of the project as it is right now—that's the final
project!
Here are the general steps you'll need to take to test each migration:
1. Delete the app from the Simulator to clear out the data store.
2. Open version 2 of the app (so you can at least see some pictures!), and build
and run.
3. Create some test notes.
4. Quit the app from Xcode and close the project.
5. Open the final version of the app, and build and run.
At that point, you should see some console output with the migration status. Note
that the migration will happen prior to the app presenting onscreen.
You now have an app that will successfully migrate between any combinations of
old data versions to the latest version.
Search WWH ::




Custom Search