gpt4 book ai didi

objective-c - RestKit:区分didLoadResponse中的多个请求:

转载 作者:太空狗 更新时间:2023-10-30 03:14:23 24 4
gpt4 key购买 nike

我想使用 RestKit 并在同一个类中处理多个不同的请求,即在 didLoadResponse: 方法中。如何区分不同的请求?我如何知道哪个请求已完成?

我正在通过

做请求
RKClient *client = [RKClient sharedClient];
[client get:@"/....", method] delegate:self];

然后,在委托(delegate)方法中

- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response {
if (???) // request which gets XY returned
...
else if (???) // request which gets YZ returned
...
}

这可能吗?

最佳答案

当然,RKClient get: 方法返回一个 RKRequest 对象。只需将 userData 设置为请求并稍后在委托(delegate)中检索它。

RKClient *client = [RKClient sharedClient];
RKRequest *request = [client get:@"/....", method] delegate:self];
[request setUserData:@"FirstRequest"];

稍后在委托(delegate)中检查

- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response {
id userData = [request userData];
if ([userData isEqual:@"FirstRequest"]) // request which gets XY returned
...
else if (...) // request which gets YZ returned
...
}

关于objective-c - RestKit:区分didLoadResponse中的多个请求:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8387253/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com