将 RestKit 从 0.10 升级到 0.20 问题 [英] Upgrading RestKit from 0.10 to 0.20 problems

查看:65
本文介绍了将 RestKit 从 0.10 升级到 0.20 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何纠正从 RestKit 0.10 升级到 0.20 后遇到的错误......有人可以帮忙吗?

谢谢!

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){
}

我看到了 GitHub 帮助页面,但我自己无法解决这个问题.真的很感谢!

更新

好的,我想我明白如何替换第一行,只需使用[RKObjectManager.sharedManager getObjectsAtPath:@"/springs/?apikey=xxx" parameters:nil 成功:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)...

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)...

但我仍然不确定如何处理 loader.onDidLoadObjects = ^(NSArray *objects) 部分!

But I'm still not sure what to do with the loader.onDidLoadObjects = ^(NSArray *objects) part!

推荐答案

您展示的 0.1x 代码下载响应数据,然后调用您的回调以询问如何处理它,因此您在回调中提供映射.

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 不是这样工作的.它在您发出请求之前将所有映射作为配置,并且这些映射与响应描述符相关联(因此 RestKit 可以搜索所有配置选项并应用匹配的所有内容).

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).

因此,在您实际从服务器获取"任何内容之前,您需要获取配置并将其应用到 RKObjectManager.

So, you need to take your configuration and apply it to the RKObjectManager before you actually 'get' any content from the server.

这篇关于将 RestKit 从 0.10 升级到 0.20 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆