Delay loading of the background context

This commit is contained in:
Jackson Harper
2024-01-04 06:09:22 +08:00
parent f95c76ff8f
commit 8a288ffe5f

View File

@ -60,16 +60,16 @@ public final class DataService: ObservableObject {
self.appEnvironment = appEnvironment
self.networker = networker
self.persistentContainer = PersistentContainer.make()
self.backgroundContext = persistentContainer.newBackgroundContext()
backgroundContext.automaticallyMergesChangesFromParent = true
backgroundContext.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump
persistentContainer.loadPersistentStores { _, error in
if let error = error {
fatalError("Core Data store failed to load with error: \(error)")
}
}
self.backgroundContext = persistentContainer.newBackgroundContext()
backgroundContext.automaticallyMergesChangesFromParent = true
backgroundContext.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump
}
public func cleanupDeletedItems(in context: NSManagedObjectContext) {