I need to use Core Data inside NSOperationQueue operations. I've heard that it's sufficient to create an NSManagedObject instance for every single NSOperation or Thread, and then Core Data won开发者_Go百科't have multithreading-problems. Is this correct?
Would the other MOC's be updated automatically when others get modified in NSOperations?
You are correct that you need a new MOC (Managed Object Context) for each thread/operation. Give the new context the same persistant store coordinator as your main context, and then when saving the contexts you need to handle the merge. See my previous answer here which explains how to perform the merge:
How to Deal with Temporary NSManagedObject instances?
Would the other MOC's be updated automatically when others get modified in NSOperations?
No. You need to handle the NSManagedObjectContextDidSaveNotification
notification and use mergeChangesFromContextDidSaveNotification:
to merge in the changes. See the documentation for details, and other methods of doing it.
精彩评论