Note that there are some explanatory texts on larger screens.

plurals
  1. PONSFetchedResultsController do not get updated when the managedobjectcontext change
    primarykey
    data
    text
    <p>I make a program where I sometimes moves some anchor to another</p> <p>When I move those anchors I would recompute distance of bizs nearby the 2 anchors (before and after anchors). The computation is done in background</p> <p>I used this standard code to update stuff</p> <pre><code>+(void)commit { // get the moc for this thread [Tools breakIfLock]; NSManagedObjectContext *moc = [self managedObjectContext]; NSThread *thread = [NSThread currentThread]; DLog(@"threadKey commit%@" , [[self class]threadKey]); if ([thread isMainThread] == NO) { // only observe notifications other than the main thread [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contextDidSave:) name:NSManagedObjectContextDidSaveNotification object:moc]; } NSError *error; if (![moc save:&amp;error]) { CLog(@"Error in Saving %@", error); DLog(@"What the hell error is it"); } else{ } if ([thread isMainThread] == NO) { [[NSNotificationCenter defaultCenter] removeObserver:self name:NSManagedObjectContextDidSaveNotification object:moc]; } //[GrabClass StopNetworkActivityIndicatorVisible]; } +(void)contextDidSave:(NSNotification*)saveNotification { dispatch_async(dispatch_get_main_queue(), ^{ BadgerNewAppDelegate *delegate = [BNUtilitiesQuick appDelegate]; DLog (@"currentThreadinContextDidSave: %@",[self threadKey]); NSManagedObjectContext *moc = delegate.managedObjectContext; //delegate for main object CLog(@"saveNotification : %@",saveNotification); [moc mergeChangesFromContextDidSaveNotification:saveNotification]; }); //[moc performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:) withObject:saveNotification waitUntilDone:YES]; } </code></pre> <p>I break point and see that distances did get updated. Everything is fine</p> <p>However the <code>NSFetchedResultsController</code> fetchedObjects doesn't seem to get updated and still use the old value.</p> <p>How can that be?</p> <p>Also the </p> <pre><code>- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { DLog(@"controllerWillChangeContent: %@", controller); [self.tableViewA beginUpdates]; } </code></pre> <p>is never called even though the <code>NSManagedObjectContext</code> has changes.</p> <p>Well actually I wasn't sure if the <code>managedObjectContext</code> has changed or not. How do I know? I mean will change in managedObjectContext ensure changes in <code>fetchController.fetchedObjects</code>.</p> <p>There is no caching as far as I know. How can I be sure of that too?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload