创建核心数据写入的后台线程 [英] Creating Background Thread for Core Data writing

查看:105
本文介绍了创建核心数据写入的后台线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重建这个三层核心数据系统,在这篇文章中描述( http://www.cocoanetics.com/2012/07/multi-context-coredata/ )。我遇到的问题是在自己的后台线程创建私有MOC。我没有多线程的经验和如何应该在目标c。我一直在阅读的文章,并试图抓住如何正确实现这种方法,但我终于承认,我不知道我在做什么。

I'm trying to recreate the three tier core data system that is described in this cocoanetics article ( http://www.cocoanetics.com/2012/07/multi-context-coredata/). The problem I'm running into is creating the private MOC on its own background thread. I don't have much experience with multithreading and how it should be done in objective c. I've been reading over articles and trying to grasp how to correctly implement this approach, but I have finally conceded to the fact that I don't know what I'm doing.

要创建这种方法,我需要创建一个NSThread并管理它吗?

To create this approach, do I need to create an NSThread and manage it? Or is there a simpler way that I'm not understanding?

推荐答案

在后台执行核心数据操作的最简单方法是以创建 NSPrivateQueueConcurrencyType 的受管对象上下文。这种类型的MOC创建和管理私有队列。使用 performBlock performBlockAndWait 在私有MOC上执行操作,确保使用正确的队列。

The easiest way to perform Core Data operations in the background is to create a managed object context of the NSPrivateQueueConcurrencyType. This type of MOC creates and manages a private queue. Using performBlock or performBlockAndWait to execute operations on the private MOC ensures that the right queue is used.

查看并发支持管理对象上下文
OS X v10.7和iOS 5.0的核心数据发行说明中详细信息和示例。

See Concurrency Support for Managed Object Contexts in the Core Data Release Notes for OS X v10.7 and iOS 5.0 for details and examples.

我只能推荐观看WWDC 2011会话303的视频或幻灯片iOS上的Core Data的新功能,其中Core Data并发

I can only recommend to watch the video or slides from the WWDC 2011 Session 303 "What’s New in Core Data on iOS", where Core Data concurrency is explained.

这篇关于创建核心数据写入的后台线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆