How to get objects after combining CoreData Context

I tried to save data and merge using CoreData and a multi-threaded application for the iPhone. But I can not get the managed objects in the main thread after the merge.

I wrote the code like this:

[managedObjectContext performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:)
                                       withObject:notification
                                    waitUntilDone:YES];

[self performSelectorOnMainThread:@selector(didMerged:) withObject:objectIds waitUntilDone:YES];

So, I tried passing objectIds to get the NSManagedObject instances in the main thread that were generated in another thread. At first I tried the "objectWithId" method, but it generated failure objects. Then I tried the "existingObjectWithID" method, but partially generated the objects, and the others were zero with the following error:

[Error] Error Domain=NSCocoaErrorDomain Code=133000 "Operation could not be completed. (Cocoa error 133000.)"

What's wrong? Is there a way to restore all objects using objectIds after merging in another thread?

Thank.

+5
3

, .

133000

NSManagedObjectReferentialIntegrityError = 133000

NSManagedObjectReferentialIntegrityError , , . , , , . Mac OS X 10.4 . CoreDataErrors.h.

+2

-, . :

NSLog(@"Error: %@\n%@", [error localizedDescription], [error userInfo]);

.

Secondly, if you work with one context in several threads, you are doing it wrong. You need to look at the documentation for master data and streaming. Basic rule: one context for the flow; Period. If you need to manage data in multiple threads, look at viewing save notifications from background threads in the main thread. I would suggest reviewing my articles on the Mac Developer Network for examples of this.

0
source

All Articles