通常有背景上下文来执行写操作。
// 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()
}我在automaticallyMergesChangesFromParent上很困惑。
作为,我在viewContext (与主队列关联的托管对象上下文)和backgroundContext上有以下观察。
viewContext.parent is nilbackgroundContext.parent is nil我的问题是
如果我们需要设置viewContext
viewContext接收来自backgroundContext的更改,这是否意味着backgroundContext不是backgroundContext的父级,viewContext.automaticallyMergesChangesFromParent = true指的是什么父级?发布于 2021-03-24 17:27:55
如果父母是零,这是零,没有隐含的父母关系。当父上下文为零时,automaticallyMergesChangesFromParent会自动合并保存到其持久存储协调器的更改。它不是父上下文,但它在这里做了一些类似父上下文的事情。只要这两个上下文使用相同的持久性存储协调器(或相同的NSPersistentContainer),那么这将自动合并更改,而不存在父上下文关系。
https://stackoverflow.com/questions/66784854
复制相似问题