Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well this is a strange one but I have got it doing what I need now. When I start the background task updating I pass it its own NSManagedObjectContext. I set my main thread as a subscriber to the save event in this NSManagedObjectContext so that I can update the main threads MOC when the background MOC actions a save.</p> <pre><code>- (void)mergeChanges:(NSNotification *)notification { DLog(@"Merge changes has begun"); // Merge changes into the main context on the main thread NSManagedObjectContext *incommingContext = [notification object]; if (incommingContext != self.managedObjectContext){ dispatch_sync(dispatch_get_main_queue(), ^{ [self.managedObjectContext mergeChangesFromContextDidSaveNotification:notification]; }); } //[self compareMOCs]; } </code></pre> <p>When you action <code>NSManagedObjectContext rollback</code> the NSManagedObjectContext does not roll back (because it is saved) but the NSFetchedResultsController does and shows up the two deleted records. </p> <p>To work around this I am having to save my main threads NSManagedObjectContext in the main thread after a save merge as so:</p> <pre><code>- (void)mergeChanges:(NSNotification *)notification { DLog(@"Merge changes has begun"); // Merge changes into the main context on the main thread NSManagedObjectContext *incommingContext = [notification object]; if (incommingContext != self.managedObjectContext){ dispatch_sync(dispatch_get_main_queue(), ^{ [self.managedObjectContext mergeChangesFromContextDidSaveNotification:notification]; // no idea why I have to do this but if I do not do this any // attempt to rollback the MOC will cause the NSFetchedResultsController to pull out // ghost records. [self.managedObjectContext save:nil]; }); } //[self compareMOCs]; } </code></pre> <p>According to Apple this should not be required as the notification is only fired after a save event on the background MOC. I cannot explain why this is happening, I can only tell you that it is happening and this extra save has fixed it.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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