I am using a NSFetchedResultsController for dealing with a UITableView and everything works fine and I found it very powerful, especially in conjunction with the results delegate. For drilling down the table I am reusing the same controller class, which get instantiated with parameters by clicking on a cell row, the controller is then pushed to the UINavigationController and another table view is built, again with a NSFetchedResultsController.
At this point, every controller has its own cache, and the cache name is derived with a unique identifier [NSString stringWithFormat"cacheName_%@",uniqueStringForCell], and in the end I can obviously have many cache.
Now the questions.
1) Having many cache can be a problem ?
2) When are we supposed to use a cache ?
3) In case of deleteCacheWithName , where's the best place to put such method ? I have tried in viewWillDisappear, but with this I suppose I can have problem when the view will appear again and the cache is not present anymore, for example when using with a UINavigationController. Probably the dealloc method is the best place ?
4) What's the relationship between a cache and memory management ? I mean, when a (void)didReceiveMemoryWarning is sent do I need to delete the cache ? If yes, what about rebuilding it again ? What's the preferred way, maybe re issuing the fetch ?
5) the fetch controller has its delegate set to the UITableViewController (fetchController.delegate=self), is there any problem with that ? In a sense that in case of change more than one controllers is alerted ? And does deleteCacheWithName also remove the delegate ?
thanks
To answer (some) your questions:
1) Having multiple caches is not a problem. In fact, from Apple's class reference:
I've had issues with previous apps where I have not done this only to get an exception that I wasted time trying to resolve.
2) We are supposed to use the cache to store any repeated work the NSFetchedResultsController needs to do. Anytime the section or ordering information changes, the cache gets updated. Similarly, if the cache is not consistent with the current information in the database (you added a new row, deleted, etc) then the controller releases the cache and clears it.
3) I've personally put deleteCacheWithName in the viewDidUnload method. Not sure if this is the best place or not though.
Not sure about 4. In terms of rebuilding the cache - this should happen automatically if the current cache is out of sync with the app. I have not done anything specific for memory management and the cache on any of my apps.
5) This should not be a problem. Again, from Apple's documentation:
FYI, here is the link to the apple dev docs for this class: http://developer.apple.com/library/ios/#documentation/CoreData/Reference/NSFetchedResultsController_Class/Reference/Reference.html
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With