Skip to content

Instantly share code, notes, and snippets.

@rayfix
Created August 5, 2011 07:23
Show Gist options
  • Save rayfix/1127067 to your computer and use it in GitHub Desktop.
Save rayfix/1127067 to your computer and use it in GitHub Desktop.
First mapping
- (void)mapObjects:(RKObjectManager*)objectManager
{
RKObjectMapping* widgetMapping = [RKObjectMapping mappingForClass:[widget class]];
[widgetMapping mapKeyPath:@"id" toAttribute:@"widgetID"];
[widgetMapping mapAttributes:@"name", @"description", nil];
[widgetMapping mapKeyPath:@"public" toAttribute:@"isPublic"];
[widgetMapping mapKeyPath:@"created_at" toAttribute:@"createdAt"];
[widgetMapping mapKeyPath:@"updated_at" toAttribute:@"updatedAt"];
[objectManager.mappingProvider setMapping:widgetMapping forKeyPath:@"widget"];
}
- (void)initRestKit
{
// Configure parser based on what is being linked
[[RKParserRegistry sharedRegistry] autoconfigure];
NSString* baseURL = [self baseURL];
// Create a client.
[RKClient setSharedClient:[[RKClient alloc] initWithBaseURL:baseURL]];
// first object manager becomes the shared instance
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL];
[objectManager setClient:[RKClient sharedClient]];
// custom configuration of the RKClient... magic headers, etc.
// ...
// This is probably redundant but it makes be feel better doing it explicitly.
[RKObjectManager setSharedManager:objectManager];
// map the widget object
[self mapObjects:objectManager];
}
// The response coming from the remote server
[{"commented_at":null,"created_at":"2011-08-04T15:35:03Z","description":"Other","id":7,"name":"Misc Widget","type_index":0,"updated_at":"2011-08-04T15:35:03Z","user_id":5},{"commented_at":null,"created_at":"2011-08-04T15:35:03Z","description":"Cool","id":6,"name":"Coolness Widget","type_index":1,"updated_at":"2011-08-04T15:35:03Z","user_id":5},{"commented_at":null,"created_at":"2011-08-04T15:35:02Z","description":"Awesome Widget","id":5,,"name":"Another Widget","type_index":0,"updated_at":"2011-08-04T15:35:03Z","user_id":5}]
// In the view controller
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"widgets.json" delegate:self];
// delegate method shoves stuff into the table view
# The error
W restkit.object_mapping:RKObjectMapper.m:90 Found a collection containing only NSNull values, considering the collection unmappable...
W restkit.object_mapping:RKObjectMapper.m:90 Found a collection containing only NSNull values, considering the collection unmappable...
W restkit.object_mapping:RKObjectMapper.m:90 Found a collection containing only NSNull values, considering the collection unmappable...
W restkit.object_mapping:RKObjectMapper.m:60 Adding mapping error: Could not find an object mapping for keyPath: ''
E restkit.network:RKObjectLoader.m:178 Encountered errors during mapping: Could not find an object mapping for keyPath: ''
Widget Load Failed: Could not find an object mapping for keyPath: ''
@rayfix
Copy link
Author

rayfix commented Aug 5, 2011

dt notes: your json response should look like {"widget":[..]}

@rayfix
Copy link
Author

rayfix commented Aug 5, 2011

dt suggests a mod to line 9
[objectManager.mappingProvider setMapping:widgetMapping forKeyPath:@""];

I tried this but I still get 2 W messages. (And my table doesn't appear to be populating.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment