Best practice when truncating during a save? #676

seivan opened this Issue Feb 14, 2014 · 2 comments


None yet
3 participants

seivan commented Feb 14, 2014

I'm having some issues with my NSFetchedResultsController.
When the user logs out which fires off a truncate on all entities - that causes an exception in any controller that might currently be in the process of updating it's data.

The exception happens in;

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
  [self.tableView endUpdates];
Assertion failure in -[UIViewAnimation initWithView:indexPath:endRect:endAlpha:startFraction:endFraction:curve:animateFromCurrentPosition:shouldDeleteAfterAnimation:editing:], /SourceCache/UIKit/UIKit-2903.23/UITableViewSupport.m:2661

Now I am sure it's my fault in the way I use Magical Record. Right now everything runs with

- (void) MR_saveToPersistentStoreWithCompletion:(MRSaveCompletionHandler)completion;

This happens after end of a network requests that has updated the existing entities.

Hi @selvan, the best solution to your problem would probably be to nil out the NSFetchedResultsController before you truncate all tables.

Another way to do this would be to use the suspendAutomaticTrackingOfChangesInManagedObjectContext property on your controller (provided you're using standard boilerplate code) and fire off notifications when you're about to change the core data stack or have just changed it to set the property accordingly.


tonyarnold commented Apr 17, 2014

@seivan — in which context are you performing the truncation? Is it the main/default context, or the root saving context, or a child of either?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment