It is common to have background context to perform write operation.
// Set automaticallyMergesChangesFromParent to true
persistentContainer.viewContext.automaticallyMergesChangesFromParent = true
persistentContainer.performBackgroundTask { backgroundcontext in
// Do your work...
let object = backgroundContext.object(with: restaurant.objectID)
backgroundContext.delete(object)
// Save changes to persistent store, update viewContext and notify fetched results controller
try? backgroundContext.save()
}
I am confused on the automaticallyMergesChangesFromParent.
As, I have the following observation on viewContext (The managed object context associated with the main queue) and backgroundContext.
viewContext.parentis nilbackgroundContext.parentis nil
My questions are
- If we need to set
viewContext.automaticallyMergesChangesFromParent = true, in order forviewContextto receive changes frombackgroundContext, does that meanbackgroundContextis the parent ofviewContext? - If not, what parent is
viewContext.automaticallyMergesChangesFromParent = truereferring to?