简体   繁体   中英

What is the most efficient way to use Core Data?

I'm developing an iPad application using Core Data, and was hoping someone could clarify something about Core Data.

Right now, I populate my table by making a fetch request for all of my data in viewDidLoad . I'd rather make individual fetch requests in my tableView:cellForRowAtIndexPath: . Can anyone tell me which is more efficient, and why? In other words, is it much less efficient to make lots of small requests as opposed to one big request?

Your fetch request has a property called fetchBatchSize that tells your fetch request only to fetch data in batches. That means for a batch size of 20, only the first 20 items are loaded into memory. When the user scrolls past 20, another 20 items are loaded automatically, and so on.

Additionally, Apple ships an NSFetchedResultsController class that is designed for managing presentation and editing of your data (it works best with table views, but can work with other kinds of view controllers, of course). It handles a lot of other optimization under the hood for you (things like batched fetching, memory management, etc), and as such offers much better performance than were you to create, initiate and manage your fetch requests yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM