views:

356

answers:

1

I have the following scenario:

  • entity with a transient attribute used for sectioning
  • web-based data model periodically refreshed
  • NSFetchedResultsController

Everything works fine, but when I do a refresh, that transient attribute seems to be getting out of date.

The attribute is returned by an accesssor in my entity object. I tried setting a breakpoint in the accessor, and notice that it's not actually called when my app starts up and my NSFetchedResultsController. This seems to indicate that Core Data is caching this value somewhere (since my table is still section properly). Is there a way to clear this cache?

+4  A: 

Yes. Use

+ (void)deleteCacheWithName:(NSString *)name;

The name is the one you provided during NSFetchedResultsController initialization time, when calling

- (id) initWithFetchRequest:(NSFetchRequest *)fetchRequest managedObjectContext:(NSManagedObjectContext *)context sectionNameKeyPath:(NSString *)sectionNameKeyPath cacheName:(NSString *)name;

setting the cacheName argument.

Alternatively, you can avoid Core Data caching the data during NSFetchedResultsController initialization time: simply pass nil for the cacheName argument.

unforgiven
This pertains to NSFetchedResultsController; is the OS caching these results between runs of the app?
Ben Gottlieb
From the NSFetchedResultsController documentation: "The cache is maintained across launches of your application".
unforgiven
Brilliant, thanks!
Ben Gottlieb