将 RestKit 从 0.10 升级到 0.20 问题

编程入门 行业动态 更新时间:2024-10-28 08:17:24
本文介绍了将 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 问题

本文发布于:2023-07-15 18:07:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1112846.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:升级到   RestKit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!