Core Data在NSOperation和sync中插入对象 [英] Core Data insert objects in NSOperation and sync

查看:134
本文介绍了Core Data在NSOperation和sync中插入对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 NSOperation 中保存网络响应中的对象。我理解对于合并MOC从后台线程到主线程的改变,我可以使用父上下文中的 mergeChangesFromContextDidSaveNotification performBlock p>

我应该如何使用 mergeChangesFromContextDidSaveNotification performBlock
每个合并方法的优点和缺点?



NSOperation 在后台上下文中执行。因此,当我调用 performBlock 将会创建新线程吗?

解决方案

搜索我的问题的答案我发现了并发核心数据Stacks Performance 文章。本文回答如果你用旧的核心数据堆栈与同步数据使用 mergeChangesFromContextDidSaveNotification 方法,你获得更好的性能。
我还发现了苹果示例 ThreadedCoreData 。在这个例子中,他们仍然使用与 mergeChangesFromContextDidSaveNotification 同步。



因此,我的问题的答案是,如果你进行性能应该使用 mergeChangesFromContextDidSaveNotification 如果你更简单的实现,你应该使用嵌套上下文。


I'm saving objects from network response in NSOperation. As I understand for merge MOC's changes from background threads to main I can use mergeChangesFromContextDidSaveNotification or performBlock with parent context.

What should I prefer to use mergeChangesFromContextDidSaveNotification or performBlock? What are the pros and cons of each merge method?

NSOperation executed in background context. So when I call performBlock will be created new thread or not?

解决方案

Searching answer on my question I found Concurrent Core Data Stacks Performance article. This article answer that if you user old core data stack with sync data using mergeChangesFromContextDidSaveNotification method you get better performance. Also I found apple example ThreadedCoreData. In this example they still using sync with mergeChangesFromContextDidSaveNotification.

So answer on my question is if you carry on performance you should use mergeChangesFromContextDidSaveNotification if you what simpler realization you should use nested contexts.

这篇关于Core Data在NSOperation和sync中插入对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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