I've recently upgraded a project from using RestKit 0.1x to 0.2x and am trying to get my head around the changes particularly in paging.
Is someone able to explain to me the following commented code? It's from RKPaginator.h:
/**
Initializes a RKPaginator object with the a provided patternURL and mappingProvider.
@param request A request with a URL containing a dynamic pattern specifying how paginated resources are to be acessed.
@param paginationMapping The pagination mapping specifying how pagination metadata is to be mapped from responses.
@param responseDescriptors An array of response descriptors describing how to map object representations loaded by object request operations dispatched by the paginator.
@return The receiver, initialized with the request, pagination mapping, and response descriptors.
*/
- (id)initWithRequest:(NSURLRequest *)request
paginationMapping:(RKObjectMapping *)paginationMapping
responseDescriptors:(NSArray *)responseDescriptors;
In particular, what I'm trying to grasp is the role of responseDescriptors.
What is a Response Descriptor? Is it the mapping of the actual objects inside the paginators object collection returned from the query? If so - I've got this mapped in the paginationMapping. Is it then the status codes? I've been through the documentation and just don't get it.
I'd really appreciate a pointer or link to an example.. I can clarify with my existing code - this is the code to load an activity stream depending on what type of stream the user has chosen... activity, project list or favourites (list of sightings)..
-(void)setPaginatorForStream:(NSString*)streamName {
[BBLog Log:@"BBStreamController.setPaginatorForStream:"];
[BBLog Debug:@"streamName:" withMessage:streamName];
__weak typeof(self) weakSelf = self;
NSString *streamUrl = [NSString stringWithFormat:@"/%@?PageSize=:perPage&Page=:currentPage", streamName];
if (!self.paginator) {
RKObjectManager *objectManager = [RKObjectManager sharedManager];
RKObjectMapping *paginationMapping = nil;
// TODO: Create response descriptors for these puppies:
if([streamName isEqualToString:@"favourites"]){ // sightings
paginationMapping = [RKObjectMapping mappingForClass:[BBSightingPaginator class]];
self.paginator = [[BBSightingPaginator alloc]initWithRequest:[NSURLRequest requestWithURL:[[NSURL alloc]initWithString:streamUrl]]
paginationMapping:paginationMapping
responseDescriptors:nil
andDelegate:weakSelf];
}
else if([streamName isEqualToString:@"projects"]){
paginationMapping = [RKObjectMapping mappingForClass:[BBProjectPaginator class]];
self.paginator = [[BBProjectPaginator alloc]initWithRequest:[NSURLRequest requestWithURL:[[NSURL alloc]initWithString:streamUrl]]
paginationMapping:paginationMapping
responseDescriptors:nil
andDelegate:weakSelf];
}
else {
paginationMapping = [RKObjectMapping mappingForClass:[BBActivityPaginator class]];
self.paginator = [[BBActivityPaginator alloc]initWithRequest:[NSURLRequest requestWithURL:[[NSURL alloc]initWithString:streamUrl]]
paginationMapping:paginationMapping
responseDescriptors:nil
andDelegate:weakSelf];
}
self.paginator.perPage = 20;
[self.paginator setCompletionBlockWithSuccess:^(RKPaginator *paginator, NSArray *objects, NSUInteger page) {
[weakSelf.tableItems addObjectsFromArray:objects];
[weakSelf.tableView reloadData];
} failure:^(RKPaginator *paginator, NSError *error) {
NSLog(@"Failure: %@", error);
}];
}
}
I've followed smakman's example on this post (https://github.com/RestKit/RestKit/issues/1035) to get this far but I am instantiating my paginators from existing mapped objects.
As you can see, I've nil'd out the responseDescriptors... what would I put there?
Many thanks, Hamish.