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
automatically
toMerges Changes From Parent 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)