A tiny tiny CoreData revelation.

Following on from the previous discovery of all the useful debugging features, including the Build & Analyze feature and the Performance Tool stuff, the argument to debug core data has one problem. It doesn’t display your parameters. So change that 1 up a bunch of times (I have it set to 5) and it becomes more useful. This led me to realise why my app crashed when making lots of edits/deletes of categories (with some rules to other data cascading deletes and some just nullifying the relevant columns. It’s all down to caching and produces this excellent error message, no sarcasm this is a fantastic error message:

2010-08-09 18:52:37.125 CC [4551:207] FATAL ERROR: The persistent cache of section information does not match the current configuration.  You have illegally mutated the NSFetchedResultsController's fetch request, its predicate, or its sort descriptor without either disabling caching or using +deleteCacheWithName:

As I jump into various sections I was setting the cache up with the name of the section. Of course depending on my search criteria the predicate (the WHERE bit of the SQL in Core Data parlance) changes. So now I build the names of the caches a bit more dynamically:

NSString *cacheName = [NSString stringWithFormat:@"TitlesIn%@",category.name]

This keeps everything really smooth when hopping around at the expense of a bit more memory usage. It’s easy enough to sort out the memory issue as well if necessary as the error message tells us how to delete caches so we could implement code to keep an eye on how often caches are hit and delete the ones that are old.

Sorted.

This entry was posted in Programming. Bookmark the permalink.