In what may well become a continuing series, I’ve got another word of warning for you about the otherwise astoundingly useful NSFetchedResultsController
(NSFRC) class. It turns out to be highly inadvisable to delete an object that’s referenced in the NSPredicate
of an NSFRC’s NSFetchRequest
. For instance, if you set up an NSFRC with code that creates a predicate like this:
request.predicate = [NSPredicate predicateWithFormat:@"ANY people == %@",somePerson];
and subsequently delete the somePerson
object (e.g. with the deleteObject:
method of NSManagedObjectContext
), then you’re setting yourself up for trouble.
Trouble
“Trouble” may only be worrying messages in the debugger such as this:
2009-10-28 18:49:28.893 Bug0[1766:20b] NSFetchedResultsController Error: expected to find object (entity: Event; id: 0xf4c880 ; data: {
children = "";
parent = nil;
timeStamp = 2009-10-28 18:49:28 -0700;
}) in section (null) for deletion
2009-10-28 18:49:28.894 Bug0[1766:20b] NSFetchedResultsController rebuilding section caches
or “trouble” may be a full-blown application crash. In any event, you want no part of it, and should therefore avoid deleting objects referenced in the NSPredicates
of the NSFetchRequests
that you use to create NSFRCs.