问题
I can't figure out how to correct the errors I'm getting after having upgraded from RestKit 0.10 to 0.20... Can anyone help?
Thanks!
ViewController.m
- (void)viewDidLoad {
// Wain, I added this RKResponseDescriptor
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor
responseDescriptorWithMapping:[Feed mapping] method:RKRequestMethodAny
pathPattern:nil keyPath:@"springs" statusCodes:nil];
// These 4 lines has errors and needs to be fixed
// No visible @interface for 'RKObjectManager' declares the selector 'loader'
[[RKObjectManager sharedManager]
loadObjectsAtResourcePath:@"/springs/?apikey=xxx"
usingBlock:^(RKObjectLoader *loader) {
loader.onDidLoadObjects = ^(NSArray *objects){
springs = objects;
// These 2 lines have errors that need to be fixed
// Use of undeclared identifier 'loader'
[loader.mappingProvider setMapping:[Spring mapping] forKeyPath:@"springs"];
loader.onDidLoadResponse = ^(RKResponse *response){
}
I see the GitHub help page for this, but I can't figure this out with just that on my own. Really appreciate it!
Update
Ok I think I understand how to replace the first line, just by using
[RKObjectManager.sharedManager getObjectsAtPath:@"/springs/?apikey=xxx" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
...
But I'm still not sure what to do with the loader.onDidLoadObjects = ^(NSArray *objects)
part!
回答1:
The 0.1x code you show downloads the response data and then calls your callback to ask what to do with it, so you supply the mapping in the callback.
0.2x doesn't work like that. It takes all of the mappings as configuration before you make the request, and the mappings are associated with response descriptors (so RestKit can search all the config options and apply everything that matches).
So, you need to take your configuration and apply it to the RKObjectManager
before you actually 'get' any content from the server.
来源:https://stackoverflow.com/questions/22739221/upgrading-restkit-from-0-10-to-0-20-problems