Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSFetchedResultsChangeUpdate fired instead of NSFetchedResultsChangeDelete

Tags:

I have a NSFetchedResultsController initiated in the following way:

NSEntityDescription *myEntity = [NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:myEntity];
[fetchRequest setFetchBatchSize:10];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"wasDeleted == %@", [NSNumber numberWithBool:NO]]];

NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES selector:@selector(caseInsensitiveCompare:)];

[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortDescriptor, nil]];

myFetchedResults = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:nil];
myFetchedResults.delegate = self;
[myFetchedResults performFetch:nil];

Some facts:

  • wasDeleted is an NSNumber property (BOOL) of MyEntity

  • If I update this property to [NSNumber numberWithBool:YES] the NSFetchedResultsControllerDelegate calls didChangeObject but firing NSFetchedResultsChangeUpdate instead of NSFetchedResultsChangeDelete.

  • However, if I pop the view and init again the fetched results controller, the object is not there anymore, showing that [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"wasDeleted == %@", [NSNumber numberWithBool:NO]]]; works.

  • After this NSFetchedResultsChangeUpdate, when cellForRow is called, I print wasDeleted and it's set to YES.

What can be wrong here?

(In other words, NSFetchedResultsChangeDelete can be called if the object still exists on the context however doesn't fit the predicate?)