diff --git a/Tusker/CoreData/MastodonCachePersistentStore.swift b/Tusker/CoreData/MastodonCachePersistentStore.swift index cb934877ed..22150e96fd 100644 --- a/Tusker/CoreData/MastodonCachePersistentStore.swift +++ b/Tusker/CoreData/MastodonCachePersistentStore.swift @@ -20,13 +20,15 @@ class MastodonCachePersistentStore: NSPersistentContainer { private(set) lazy var backgroundContext: NSManagedObjectContext = { let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType) - context.parent = self.viewContext + context.persistentStoreCoordinator = self.persistentStoreCoordinator + context.automaticallyMergesChangesFromParent = true return context }() private(set) lazy var prefetchBackgroundContext: NSManagedObjectContext = { let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType) - context.parent = self.viewContext + context.persistentStoreCoordinator = self.persistentStoreCoordinator + context.automaticallyMergesChangesFromParent = true return context }() @@ -51,6 +53,8 @@ class MastodonCachePersistentStore: NSPersistentContainer { } } + viewContext.automaticallyMergesChangesFromParent = true + NotificationCenter.default.addObserver(self, selector: #selector(managedObjectsDidChange), name: .NSManagedObjectContextObjectsDidChange, object: viewContext) }