Note that there are some explanatory texts on larger screens.

plurals
  1. PONon-deprecated means of setting object mapping
    text
    copied!<p>I have a Ruby On Rails local server running which serves me the following JSON:</p> <pre><code>[ { "content" : "Here is content", "created_at" : "2012-10-07T01:06:51Z", "id" : 4, "name" : "Joe", "title" : "Title 1", "updated_at" : "2012-10-07T01:06:51Z" }, { "content" : "Here is content", "created_at" : "2012-10-07T01:07:09Z", "id" : 5, "name" : "John", "title" : "Title2", "updated_at" : "2012-10-07T01:07:09Z" } ] </code></pre> <p>I am using RestKit to parse this into <code>Post</code> model objects like so:</p> <pre><code>- (void)loadObjects { RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[Post class]]; [objectMapping mapKeyPath:@"id" toAttribute:@"postId"]; [objectMapping mapKeyPath:@"created_at" toAttribute:@"createdAt"]; [objectMapping mapKeyPath:@"content" toAttribute:@"content"]; [objectMapping mapKeyPath:@"title" toAttribute:@"title"]; [objectMapping mapKeyPath:@"name" toAttribute:@"name"]; [objectMapping mapKeyPath:@"updated_at" toAttribute:@"updatedAt"]; RKObjectManager* manager = [RKObjectManager objectManagerWithBaseURLString:@"http://localhost:3000/"]; [manager loadObjectsAtResourcePath:@"/posts" objectMapping:objectMapping delegate:self]; } - (void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects { NSLog(@"%@", objects); } </code></pre> <p>This works fine, however the <code>loadObjectsAtResourcePath:objectMapping:delegate:</code> is deprecated. I assume I should therefore be using <code>loadObjectsAtResourcePath:delegate:</code>, but I cannot figure out a way to set the <code>objectMapping</code>. Any thoughts?</p> <p><strong>Update</strong></p> <p>I am now setting the delegate like so:</p> <pre><code>[manager loadObjectsAtResourcePath:@"/posts" usingBlock:^(RKObjectLoader *loader) { loader.objectMapping = objectMapping; loader.delegate = self; }]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload