开发者

What is the most efficient way to use Core Data?

开发者 https://www.devze.com 2023-02-01 04:42 出处:网络
I\'m developing an iPad application using Core Data, and was hoping someone could clarify something about Core Data.开发者_如何学JAVA

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

开发者_如何学JAVA

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消