Parent/Child NSManagedObjectContext Design

In the previous section, you saw how to consume changes from one context into another. With iOS 5.0, Core Data added another option to handle change notifications. Instead of having every context talk directly to the NSPersistentStoreCoordinator, we can chain contexts together in a parent/child design.

Each child context will request objects from its parent context, and if that parent context doesn’t have the objects requested, it will pass that request up the chain until it hits the NSPersistentStoreCoordinator and I/O is performed. However, if the parent context does have a reference to the desired objects, then they’re returned to the child without I/O being performed.

Further, when a child makes ...

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.