在 Restkit 中使用块(如 ASIHttpRequest 块)
我一直在 ASIHttpRequest 中广泛使用块支持,并且我发现它是一种非常优雅的异步请求编码方式,比让委托回调单独的函数要好得多。
下面是供快速参考的示例代码。
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
NSString *responseString = [request responseString];
}];
[request startAsynchronous];
我想开始使用 Restkit,但我也需要能够将 Restkit 与块一起使用。
我在这里看到了包装器 Restkit 块包装器,但想检查该包装器在生产中是否能正常工作,如果有人以前广泛使用过它
i have been using the block support extensively in ASIHttpRequest, and i have found it to be an extremely elegant way of coding async requests, much more so than having the delegate call back a seperate function
Here is the example code for quick reference.
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
NSString *responseString = [request responseString];
}];
[request startAsynchronous];
I would like to start using Restkit, but I need to be able to use Restkit with blocks as well.
I have seen the wrapper here Restkit Block Wrapper, but would like to check if that wrapper would work well in production, and if anyone have used it extensively before
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我还没有使用过 RestKit Block 包装器,但很快就会使用。我实际上正在从我的应用程序中删除 ASIHTTPRequest 并替换为 RestKit。并不是因为它不好,ASIHTTP* 相当稳定 - 但它并没有发展。虽然许多其他库(如 RestKit)包装 NSURLConnection 并因此获得 Apple 对其持续增强的好处,但 ASIHTTP* 使用 CFNetwork。 Apple 并没有投入大量精力来改进现有的 Core Foundation 类(如 CFNetwork)。此外,由于 ASIHTTP* 依赖于 CF,因此在 ARC 可用时迁移到 ARC 将是一件巨大的痛苦;我不想尽快享受ARC的好处。
I have not used the RestKit Block wrapper yet, but I will be shortly. I'm actually removing ASIHTTPRequest from my App and replacing with RestKit. Not because it's bad, ASIHTTP* is quite stable - but it isn't evolving. While many other libraries, like RestKit, wrap NSURLConnection and so reap the benefits of Apples continuing enhancements to it, ASIHTTP* uses CFNetwork. Apple isn't investing a lot of effort in improving preexisting Core Foundation classes (like CFNetwork). Also, since ASIHTTP* depends on CF, it's going to be a royal pain to migrate to ARC when it's available; I wan't the benefits of ARC as soon as possible.
对 RKRequest 和 RKObjectLoader 上所有基本委托任务的块支持将于 0.9.4 中提供
Blocks support for all the basic delegate tasks on RKRequest and RKObjectLoader will be coming in 0.9.4
昨天,Blake 发布了版本 0.9.3,其中使用了块对象映射器(其他方法已经准备好块)。您应该看看新功能。
Yesterday, Blake released verson 0.9.3 which features the usage of blocks for the Object Mapper (other methods were already ready for blocks). You should take look at the new features.
对于将 RestKit 与块一起使用的快速代码示例,我从 派生了此代码片段http://kalapun.com/blog/2012/05/17/how-i-restkit/
For a quick code sample to use RestKit with blocks, I derived this snippet from http://kalapun.com/blog/2012/05/17/how-i-restkit/