我阅读了此article,将对象保存在后台的Core Data数据库中。

在文章的最后,他们有以下代码可在后台保存数据:

[temporaryContext performBlock:^{
   // do something that takes some time asynchronously using the temp context

我了解,如果我们使用performBlock,则该操作将异步完成,但是在哪个队列中?我需要像这样将其放在后台线程中吗:
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), { () -> Void in
            temporaryContext.performBlock({ () -> Void in

            })
        })

或足以使用:
temporaryContext.performBlock({ () -> Void in

                })

最佳答案

使用就足够了:

temporaryContext.performBlock({ () -> Void in

})

您的代码将在与临时上下文关联的队列中调用。临时上下文是一个NSManagedObjectContext,它具有自己的专用队列(NSPrivateQueueConcurrencyType)

关于ios - NSMangedObjectContext performBlock在后台发行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32625878/

10-08 21:08