Created
September 5, 2012 12:45
-
-
Save rubyist/3636038 to your computer and use it in GitHub Desktop.
Basic structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
objectManager = [RKObjectManager managerWithBaseURLString:kAPIBaseURL]; | |
objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:kDataStore]; | |
objectManager.objectStore = objectStore; | |
// Set up object mappings, relationships, etc. e.g. | |
RKObjectMapping *collectionMapping = [Item mappingInStore:objectStore]; | |
// Pagination mapping | |
RKObjectMapping *paginationMapping = [RKObjectMapping mappingForClass:[RKObjectPaginator class]]; | |
[paginationMapping mapKeyPath:@"pagination.page" toAttribute:@"currentPage"]; | |
[paginationMapping mapKeyPath:@"pagination.per_page" toAttribute:@"perPage"]; | |
[paginationMapping mapKeyPath:@"pagination.items" toAttribute:@"objectCount"]; | |
[objectManager.mappingProvider setPaginationMapping:paginationMapping]; | |
[objectManager.mappingProvider setMapping:collectionMapping forKeyPath:@"items"]; | |
NSString *paginatedResource = [[NSString alloc] initWithFormat:@"%@?page=:currentPage&per_page=:perPage", [self collectionPath]]; | |
objectPaginator = [objectManager paginatorWithResourcePathPattern:paginatedResource]; | |
objectPaginator.delegate = self; | |
objectPaginator.objectStore = objectStore; | |
[objectPaginator loadPage:1]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment