NSManagedObjectContext 和 GCD
来自苹果的 核心数据编程指南:
你应该给每个线程自己的 完全私有的管理对象 上下文并保持关联 对象图分离在 每个线程的基础。
这如何扩展到 Grand Central Dispatch,您完全无法控制代表您自动创建的线程?
我现在的做法是为每个调度队列分配一个 NSManagedObjectContext,但这就是问题所在:调度队列不一定每次都使用相同的线程,对吧?
From Apple's Core Data Programming Guide:
You should give each thread its own
entirely private managed object
context and keep their associated
object graphs separated on a
per-thread basis.
How does that scale to Grand Central Dispatch, where you have absolutely no control over threads, which are created automagically on your behalf?
The way I do it now is to have one NSManagedObjectContext
for each dispatch queue, but that's the thing: a dispatch queue doesn't necessarily use the same thread every time, right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为“什么Apple 说 NSManagedObjectContext 由创建它的线程或队列拥有时是什么意思?” on SO 将回答您的问题。
I think "What does Apple mean when they say that a NSManagedObjectContext is owned by the thread or queue that created it?" on SO will answer your question.
我没有看过这篇文章,但也许您对这篇文章感兴趣 在 iPhone 上传递 NSManagedObjectContext 作者:Marcus Zara。
I have not looked at this article, but maybe you are interested in this post Passing around a NSManagedObjectContext on the iPhone by Marcus Zara.