automaticallyMergesChangesFromParent

Working with NSPersisentCoordinator?

lazy public var viewContext: NSManagedObjectContext = {
    let viewContext = self.persistentContainer.viewContext
    viewContext.automaticallyMergesChangesFromParent = true
    return viewContext
}()

I suggest setting automaticallyMergesChangesFromParent so it can observe changes from the parent store. It’s also a good prereq for using the new newBackgroundContext() function because instead of spawning a child from the View Context, it spawns a private MOC directly from the persistent store (so no parent!).

It took me a good while to realize that!

Update 12/7/21: Well, with Xcode 13.2 — some 6 years later — we finally get this behavior by default in our Xcode templates. From Apple’s release notes:

The SwiftUI Core Data templates now set automaticallyMergesChangesFromParentto true on their view context, so changes are visible in the view context as they occur, including when you use Core Data with CloudKit. (73022349) (FB8967865)

I am Dan Griffin and you can find me on Mastodon

The Blog

Base & Elevated System (and Grouped!) Background Colors

In iOS 13, Apple introduced a slew of new colors that are also dynamic – meaning they will adjust between light and dark modes (and other scenarios, such as high contrast). Of the new colors, the various background colors are pretty pecular: iOS defines two sets of background colors—system and grouped—each of which contains primary,…

iOS iOS 13

Always Taking Inquiries

At the moment I am not taking on many new projects, but am still available for inquiry or questions.

Reach Out To Dan