I could make some progress with pagination, but not completed.
If the fetch request has fetchLimit and fetchOffset not equal zero, it will create the parameters on request.
So, on my AFRESTClient
subclass, before creating the request, on the method -requestForFetchRequest:withContext:
I set the paginator as:
NSMutableDictionary *mutableParameters = [NSMutableDictionary dictionary];
self.paginator = [AFPageAndPerPagePaginator paginatorWithPageParameter:@"page" perPageParameter:@"per"];
[mutableParameters addEntriesFromDictionary:[self.paginator parametersForFetchRequest:fetchRequest]];
request = [self requestWithMethod:@"GET" path:@"feed" parameters:mutableParameters];
This will generate a request for something like http://domain.com/feed?page=1&per=20
. The page is calculated based on fetchOffset
and FetchLimit
as
NSUInteger perPage = fetchRequest.fetchLimit == 0 ? kAFPaginationDefaultPerPage : fetchRequest.fetchLimit;
NSUInteger page = fetchRequest.fetchOffset == 0 ? kAFPaginationDefaultPage : (NSUInteger)floorf((float)fetchRequest.fetchOffset / (float)perPage) + 1;
So, I could make the fetch ask for a different page, but as I'm using a NSFetchedResultsController
I couldn't make it ask for another page when I scroll a UITableView
. I tried to do something as:
[NSFetchedResultsController deleteCacheWithName:[self.fetchedResultsController cacheName]];
self.fetchedResultsController.fetchRequest.fetchOffset = self.visibleChunk * self.chunkSize;
[_fetchedResultsController performSelectorOnMainThread:@selector(performFetch:) withObject:nil waitUntilDone:NO modes:@[ NSRunLoopCommonModes ]];
Here, visibleChunk
should be used to bring another page, and chunkSize
is the number of desired itens one API request.
This is not direct a response for your question, but I hope it can help you find the answer and post here :)
If I find something more, I update this.