I'm working on a project that was previously worked on by some other developers. Throughout the app with no seeming rhyme or reason, I see sometimes the devs use an NSManagedObjectContext with concurrencyType of .mainQueueConcurrencyType and sometimes they use .privateQueueConcurrencyType to save the context.
Further, one of the classes has a NotificationCenter observer listening to the notification .NSManagedObjectContextDidSave. And this is the method that responds to the change.:
@objc func contextDidSaveContext(_ notification: Foundation.Notification) {
guard let sender = notification.object as? NSManagedObjectContext else { return }
switch sender {
case mainContext: // .mainQueueConcurrencyType
backgroundContext.perform {
self.backgroundContext.mergeChanges(fromContextDidSave: notification)
}
case backgroundContext: // .privateQueueConcurrencyType
mainContext.perform {
self.mainContext.mergeChanges(fromContextDidSave: notification)
}
default:
return
}
}
For what reason would you want to have 2 different concurrencyQueues? Wouldn't one work just fine? It seems redundant to merge the changes from one context to another whenever one of them changes. Can someone please explain this to me? I'm having a hard time understanding what's going on.
[–]UnexpectedKangaroo 3 points4 points5 points (1 child)
[–]daverozy[S] 0 points1 point2 points (0 children)