RestKit:区分didLoadResponse中的多个请求:
我想使用 RestKit 并在同一类中处理多个不同的请求,即在 didLoadResponse:
方法中。如何区分不同的请求?我如何知道哪个请求已完成?
执行请求
RKClient *client = [RKClient sharedClient];
[client get:@"/....", method] delegate:self];
我正在通过然后,在委托方法中
- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response {
if (???) // request which gets XY returned
...
else if (???) // request which gets YZ returned
...
}
,这可能吗?
I'd like to use RestKit and handle several different requests in the same class, i.e. in the didLoadResponse:
method. How can I distinguish between the different requests? How do I know which request is finished?
I'm doing the request via
RKClient *client = [RKClient sharedClient];
[client get:@"/....", method] delegate:self];
Then, in the delegate-method
- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response {
if (???) // request which gets XY returned
...
else if (???) // request which gets YZ returned
...
}
is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,
RKClient get:
方法返回一个 RKRequest 对象。只需将 userData 设置为请求并稍后在委托中检索它即可。稍后在委托中检查它
Sure, the
RKClient get:
method returns a RKRequest object. Just set a userData to the request and retrieve it later in the delegate.and check it later in the delegate
这不是您问题的确切答案,但我感觉有些人会像我一样来到这里想知道如何区分 didLoadObjects 中的多个请求。解决方案是使用 isKindOfClass。
例如,当用户登录我的应用程序时,我会进行两次 HTTP 调用,并且我想区分从 getUser 调用返回的对象与 getSummary 返回的对象(因为如果我不这样做,那么它就会崩溃)。此代码检查返回的对象是否是该特定类的“某种”,如果是,则将该对象设置为该对象的本地实例。
This isn't an exact answer to your question, but I have the feeling that some people will come here wondering how to distinguish multiple requests in didLoadObjects, as I did. The solution is to use
isKindOfClass
.For example, I make two HTTP calls when a user logs into my app, and I want to distinguish the object returned from the getUser call from the object returned by getSummary (because if I don't then it crashes). This code checks if the returned object is a "kind of" that particular class, and if so sets the object to a local instance of that object.