Limit the returned result set in CoreData

In CoreData, if I want to limit the returned result set to 100, is it enough to set the sampling limit to 100, or do I also need to set the batch size to 100?

+6
iphone core-data
source share
1 answer

It is enough to set the sampling limit to 100.

Setting the batch size does something else completely. Setting the batch size to 100 (and restricting the selection to more than 100) will allow you to get more than 100 items, but only read 100 of them into memory at a time. (The initial search, which will retrieve more than 100 objects, extracts their identifiers, not all objects.) From the documents for -fetchBatchSize:

If you set a nonzero batch size, the collection of objects returned when the selection is performed is split into batches. When the selection is complete, the entire query is evaluated and the identities of all matching objects recorded, but no more than the batch format, the objects will be retrieved from the persistent storage at a time.

+9
source share

All Articles