• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Object is not reachable from this managed object context
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Object is not reachable from this managed object context


  • Subject: Re: Object is not reachable from this managed object context
  • From: Lakshmi Vyasarajan <email@hidden>
  • Date: Sat, 18 Oct 2008 20:11:41 -0700

"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];
}@catch(NSException * exception){

NSLog([exception reason]);
@throw;
}@finally{
[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 (email@hidden)

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:
This email sent to email@hidden


References: 
 >Object is not reachable from this managed object context (From: Lakshmi Vyasarajan <email@hidden>)
 >Re: Object is not reachable from this managed object context (From: Hal Mueller <email@hidden>)

  • Prev by Date: Views, frames, and bounds
  • Next by Date: Re: What is "A class which must be subclassed" ?
  • Previous by thread: Re: Object is not reachable from this managed object context
  • Next by thread: Error in NSTask launch
  • Index(es):
    • Date
    • Thread