Fundamentals of Core Data Versioning

We’ve seen the nuts and bolts, but what’s the magic behind all of this? How does the data migration actually work? As we already explored in Chapter 2, Under the Hood, Core Data works with MOM (NSManagedObjectModel) objects that describe the data entities, their attributes, and their relationships.

Core Data versioning works with those same MOM objects but takes the design one step further.

Each entity version in each data model has a unique hash.

When Core Data loads a persistent store from disk, it resolves the matching hashes in the persistent store against the MOM objects included with the application.

If the matching MOM isn’t flagged as the “current” MOM, data migration will then kick in.

How Data ...

Get Core Data in Swift now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.