Limit the returned resultset in CoreData
In CoreData, if I want to limit the returned resultset to 100, is it enough to just set the fetch limit t开发者_StackOverflowo 100, or do I need to set the fetch batch size to 100 as well?
It is enough to set the fetch limit to 100.
Setting the fetch batch size does something else entirely. Setting the fetch batch size to 100 (and the fetch limit to something bigger than 100) would let you retrieve more than 100 items, but only reading 100 of them into memory at a time. (The initial retrieval, which would fetch more than the 100 objects, fetches their ids, not the entire objects.) From the docs for -fetchBatchSize:
If you set a non-zero batch size, the collection of objects returned when the fetch is executed is broken into batches. When the fetch is executed, the entire request is evaluated and the identities of all matching objects recorded, but no more than batchSize objects’ data will be fetched from the persistent store at a time.
精彩评论