导入Core Data中的大数据集
我正在尝试根据此导入大量数据 解决方案。 建议每个导入线程都应该有自己的managedObjectContext
,并且它们之间不能传递任何managementObject
。所以,我的问题是,如果两个对象是在不同的 MOC 中创建的,我们如何设置关系?
PS:线程中保存MOC后,通知主MOC合并上下文。因此新对象的相关对象始终位于主 MOC 中。换句话说,相关对象已经创建。
I'm trying to import large amout of data according to this solution. It is suggested that each importing threads should have its own managedObjectContext
and they cannot pass any managedObject
among them. So, my question is how we can set the relationship if two objects was created in different MOCs?
PS: After saving MOC in thread, it notifies the main MOC to merge the contexts. So related object for new object is always located in main MOC. In other words related object has already been created.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法在线程之间传递
NSManagedObject
,但可以传递NSManagedObjectID
。传递这些对象,然后从要在其中设置关系的上下文中检索对象本身。
You can't pass
NSManagedObject
s between threads, but you can passNSManagedObjectID
s.Pass those over, and then retrieve the objects themselves from the context that you want to set the relationship within.