Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data batch size

Tags:

core-data

I'm new to Core Data. I'm working against a large database, so batching/faulting mechanism is important to me.

I understand how this works when using an NSFetchedResultsController paired with a UITableView, but what if I'm not using this pairing, i.e. what if I'm allowing users to navigate sequentially through a detail view controller (similar to how Apple's Mail program does it at the message level)?

Right now, I load the sorted fetch results into an NSArray and can traverse that as needed. But if I limit the batch size to 20 for the fetched results, what do I do when the user wants to navigate to object # 21?

like image 554
wayne Avatar asked May 03 '11 04:05

wayne


2 Answers

While NSFetchedResultsController is designed to be used with a UITableView, you can still use it stand alone.

When creating a fetch request, setLimit determines how many total objects are returned. setBatchSize determines how many of those objects are un-faulted at a time. So, initially, all but the first 20 objects retrieved will be returned as faults. When you access item 21, it will fetch (un-fault) another 20 objects in the results set.

like image 145
Scott Ahten Avatar answered Nov 19 '22 16:11

Scott Ahten


You use the fetchOffSet method to have the fetch request start the next batch fetch after the point you've already fetched.

like image 37
TechZen Avatar answered Nov 19 '22 14:11

TechZen