I use NSFetchedResultsController to display heaps of objects that are partitioned using dates. With a new installation, everything works fine, and the objects are displayed in a table. However, it seems that when the application restarts, I get a crash. I specify the cache when initializing the NSFetchedResultsController, and when I do not, it works fine.
This is how I create my NSFetchedResultsController:
- (NSFetchedResultsController *)results { // If we are not nil, stop here if (results != nil) return results; // Create the fetch request, entity and sort descriptors NSFetchRequest *fetch = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:self.managedObjectContext]; NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"utc_start" ascending:YES]; NSArray *descriptors = [[NSArray alloc] initWithObjects:descriptor, nil]; // Set properties on the fetch [fetch setEntity:entity]; [fetch setSortDescriptors:descriptors]; // Create a fresh fetched results controller NSFetchedResultsController *fetched = [[NSFetchedResultsController alloc] initWithFetchRequest:fetch managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"day" cacheName:@"Events"]; fetched.delegate = self; self.results = fetched; // Release objects and return our controller [fetched release]; [fetch release]; [descriptor release]; [descriptors release]; return results; }
These are the messages I receive when the application crashes:
FATAL ERROR: The persistent cache of section information does not match the current configuration. You have illegally mutated the NSFetchedResultsController fetch request, its predicate, or its sort descriptor without either disabling caching or using +deleteCacheWithName: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'FATAL ERROR: The persistent cache of section information does not match the current configuration. You have illegally mutated the NSFetchedResultsController fetch request, its predicate, or its sort descriptor without either disabling caching or using +deleteCacheWithName:'
I really donโt know why it says that because I donโt believe that I am doing something special that can cause this. The only potential problem is the section heading (day) that I create, like this, creating a new object:
// Set the new format [formatter setDateFormat:@"dd MMMM"]; // Set the day of the event [event setValue:[formatter stringFromDate:[event valueForKey:@"utc_start"]] forKey:@"day"];
As I mentioned, all this works great if there is no cache. Any help appreciated!
objective-c iphone core-data nsfetchedresultscontroller
Oliver Apr 25 '10 at 20:09 2010-04-25 20:09
source share