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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.