Created
February 2, 2013 05:19
-
-
Save blakewatters/4696204 to your computer and use it in GitHub Desktop.
This file contains 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
// JSON loaded from '/posts/:postID/tags' looks like: | |
// [{ "name": "development" }, { "name": "restkit" }] | |
RKManagedObjectStore *managedObjectStore = [RKManagedObjectStore defaultStore]; | |
RKEntityMapping *tagMapping = [RKEntityMapping mappingForEntityForName:@"Tag" inManagedObjectStore:managedObjectStore]; | |
[tagMapping addAttributeMappingsFromDictionary:@{ @"@metadata.routing.parameters.postID": @"postID", @"name": @"name" }]; | |
[tagMapping addConnectionForRelationship:@"posts" connectedBy:@{ @"postID": @"postID" }]; | |
RKObjectManager *objectManager = [RKObjectManager sharedManager]; | |
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:tagMapping pathPattern:@"/posts/:postID/tags" keyPath:nil statusCodes:[NSIndexSet indexSetWithIndex:200]]; | |
[objectManager addResponseDescriptor:responseDescriptor]; | |
[objectManager.router.routeSet addRoute:[RKRoute routeWithRelationshipName:@"tags" objectClass:[RKPost class] pathPattern:@"/posts/:postID/tags" method:RKRequestMethodGET]]; | |
NSManagedObject *post = [NSEntityDescription insertNewObjectForEntityForName:@"Post" inManagedObjectContext:managedObjectStore.mainQueueManagedObjectContext]; | |
[post setValue:@"The Post" forKey:@"title"]; | |
[post setValue:@(1234) forKey:@"postID"]; | |
[objectManager getObjectsAtPathForRelationship:@"tags" ofObject:post parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *blockMappingResult) { | |
// Objects loaded from /posts/1234/tags are returned | |
} failure:nil]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment