Search code examples
ioscore-datansfetchrequest

Core Data, Fetch only 15 rows, and then the next 15 fetched on event trigger


I have pagination implemented in the backend, and i get the cells from the server.

The data is divided into batches, and i have to check, if the batch already exists in the database, i dont have to fetch that from the server.

To make that work , i need to just fetch first 15 rows, and then get the next 15 on event trigger.

is there any way to do so?

[fetchRequest setFetchBatchSize:15];

The above keeps fetching automatically as we scroll.


Solution

  • start with setting the request's fetch offset to 0 with a fetchLimit to 15 and just add 15 to the fetchOffset each time... Hope this helps

    // first fetch
    request.fetchOffset = 0;
    request.fetchLimit = 15;
    
    // second fetch
    request.fetchOffset = 15;
    request.fetchLimit = 15;
    
    // third fetch
    request.fetchOffset = 30;
    request.fetchLimit = 15;