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!

Posted in iOS