【发布时间】:2018-08-12 05:41:28
【问题描述】:
我有点不确定我是否理解 Core Data 中 perform() 和 performAndWait() 函数的概念。
我们可以有两种类型的上下文:
1) .mainQueueConcurrencyType (main Queue)
2) .privateQueueConcurrencyType (background Queue)
对于这两种情况,我都能理解 performAndWait() 的目的 它等待执行块代码,然后继续。
对于 privateQueueConcurrencyType,文档说:
The NSPrivateQueueConcurrencyType configuration creates its own queue upon initialization and can be used only on that queue. Because the queue is private and internal to the NSManagedObjectContext instance, it can only be accessed through the performBlock: and the performBlockAndWait: methods.
但是 mainQueue 中 perform() 的目的是什么?
当我们在 mainQueue 上有一个上下文并且我们更新/删除/任何一个 NSManagedObject 时,mainQueue 上不会发生这种情况吗?那么 perform() 的目的是什么?
【问题讨论】:
-
一个优点是您不必关心您当前所在的队列。 CoreData 为您处理。
-
但是当我在上下文(主)中更新 NSManagedObject 时,我必须使用 perform() 吗?有什么区别吗?
-
没有。您不必这样做。