Thursday, July 7, 2016

Concurrent Core Data, Now Easier Than Ever

Arkadiusz Holko:

Our main thread-bounded operations use viewContext. Background work can be performed on a context returned by the factory method newBackgroundContext(). However, usage of performBackgroundTask(_:) is recommended because of the under-the-hood optimizations.

All contexts are independent of each other, there are no parent/child relationships here. To receive changes from other contexts we simply set automaticallyMergesChangesFromParent flag to true on a context. Despite its name (*FromParent*), it works correctly with the NSPersistentContainer setup in which contexts are siblings:

Not sure I understand that last bit.

Update (2016-07-07): James O’Leary says that, despite the name of the property, it treats the persistent store itself as an implicit parent context.

Comments RSS · Twitter

Leave a Comment