Cocoa Touch: When is the NSFetchedResultsController needed to control the extraction of Core Data?

I am developing an application for the iPhone that makes extensive use of Core Data, mainly for its database-like functions (for example, the ability to set the sort order or predicate for select queries). I present all the data that I get in different UITableViewControllers.

What I would like to know is a rough idea of ​​how many objects I can retrieve before it becomes a good idea to use NSFetchedResultsController to process the request. Core Data docs say SQLite storages say that "10,000 objects are a fairly small data set," but the documentation for NSFetchedResultsController mentions storing "dozens of objects" in memory at a time.

I deal primarily with data sets of up to fifty objects, each of which can have a dozen instances of NSNumber and NSString, as well as a one-to-many relationship for the next set of objects (that is, there are twenty instances of object A, each of which has to-many relation to a set of thirty (separate) instances of object B, each of which ...).

Is this script suitable for using NSFetchedResultsController, or can I get away with a simple NSArray of results? I have no problem managing subtleties of the controller (convenient methods for getting an object for the UITableView index path, adding new objects to the context, etc.), I'm just interested in using memory for each approach.

I should mention that the application will be primarily intended for iPhone 3G (not S) and first-generation iPod users, so please keep the limited memory of these platforms in mind.

+6
memory-management iphone cocoa-touch core-data
Aug 12 '09 at 0:47
source share
1 answer

NSFetchedResultsController is an incredibly convenient helper class for interacting with master data with your UITableView. My recommendation would be to use it with every Core Data-enabled table view. In each case in which I used it, it significantly reduced the amount of code I had to write.

In terms of performance, this can lead to significant improvement. Instead of retrieving data in the entire dataset, if you use -setFetchBatchSize: with the NSFetchRequest that you pass to NSFetchedResultsController, you can perform selective fetching when only the relevant data displayed in your table view is retrieved. Data that is no longer displayed can also be deleted from memory automatically (or as I understand it).

For tables with moderate or large data sets, this can lead to significant performance gains. Apple engineers said that for a database of 10,000 items, this could reduce load time by more than 80%, and memory usage by 50%.

+11
Aug 12 '09 at 1:45
source share
— -



All Articles