简体   繁体   English

将RestKit从0.10升级到0.20的问题

[英]Upgrading RestKit from 0.10 to 0.20 problems

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? 从RestKit 0.10升级到0.20后,我不知道如何纠正出现的错误...有人可以帮忙吗?

Thanks! 谢谢!

ViewController.m 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. 我看到了GitHub帮助页面,但仅靠我自己无法解决这个问题。 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) ... 好的,我认为我了解如何替换第一行,只需使用[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! 但是我仍然不确定如何使用loader.onDidLoadObjects = ^(NSArray *objects)部分!

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.1x代码将下载响应数据,然后调用回调以询问如何处理它,因此您在回调中提供了映射。

0.2x doesn't work like that. 0.2x不能那样工作。 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). 在发出请求之前,它将所有映射作为配置,并且映射与响应描述符关联(因此RestKit可以搜索所有配置选项并应用所有匹配项)。

So, you need to take your configuration and apply it to the RKObjectManager before you actually 'get' any content from the server. 因此,您需要先进行配置并将其应用到RKObjectManager然后才能从服务器实际“获取”任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM