Search code examples
iphonecore-datansmanagedobjectcontextlarge-data

Importing Large Dataset in Core Data


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.


Solution

  • You can't pass NSManagedObjects between threads, but you can pass NSManagedObjectIDs.

    Pass those over, and then retrieve the objects themselves from the context that you want to set the relationship within.