"It looks to me like you are sharing one MOC between two threads (the web service update worker thread and the main thread). You need two MOC's. Write from the worker thread to the worker thread's MOC, then tell the main thread to refresh."

I do have two MOC's. Would be kinda weird to get "Object is not reachable from this managed object context" error if I had only one MOC. I am actually rewriting the sync portion of the app to do the save on the main thread following the strong discouragement from the docs and this forum regarding background saves.



But, would be nice to know what causes the "not reachable"  error.
*****************************************************************************************************************************
Original message:


I am developing an application that imports / synchronizes data from a web service . I have a worker thread performing the poll / sync routine. After I do the sync I refresh the main thread by calling mergeChangesFromContextDidSaveNotification.

I get an exception with reason [Object is not reachable from this managed object context]. In the following code, saveComplete is the handler for NSManagedObjectContextDidSaveNotification.

-(void)saveComplete:(NSNotification *)notification{
[self performSelectorOnMainThread:@selector(saveOnMain:) withObject:notification waitUntilDone:YES];
}

-(void)saveOnMain:(NSNotification *)notification{
        NSLog(@"Refreshing main thread");
NSManagedObjectContext * appContext = [[NSApp delegate] managedObjectContext];
        [appContext lock];
        @try{
[appContext mergeChangesFromContextDidSaveNotification:notification];
        [EMAIL PROTECTED](NSException * exception){
        
                NSLog([exception reason]);
                @throw;
        [EMAIL PROTECTED]
                        [appContext unlock];                            
        }


        NSLog(@"Refresh suceeded");
}

I could not find any references to this error leading me to believe that I am doing something completely wrong and I have no clue what it is.

On Oct 16, 2008, at 21:13, Hal Mueller wrote:

It looks to me like you are sharing one MOC between two threads (the web service update worker thread and the main thread). You need two MOC's. Write from the worker thread to the worker thread's MOC, then tell the main thread to refresh.

Hal


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to