【发布时间】:2021-06-21 09:19:23
【问题描述】:
通常有后台上下文来执行写操作。
// 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()
}
我对@987654322@ 感到困惑。
我对@987654323@(与主队列关联的托管对象上下文)和backgroundContext有以下观察。
-
viewContext.parent为零 -
backgroundContext.parent为零
我的问题是
- 如果我们需要设置
viewContext.automaticallyMergesChangesFromParent = true,以便viewContext接收来自backgroundContext的更改,这是否意味着backgroundContext是viewContext的父级? - 如果不是,
viewContext.automaticallyMergesChangesFromParent = true指的是哪个父级?
【问题讨论】: