使用 ASIHTTPRequest 作为 NSDictionary Key
我尝试使用 ASIHTTPRequest/ASIFormDataRequest
作为 NSDictionary 中的键,如下所示:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:GPUserData.userlogin forKey:@"username"];
[request setPostValue:GPUserData.password forKey:@"password"];
[request setDelegate:self];
[_delegates setObject:delegate forKey:request];
[_selectors setObject:[NSValue valueWithPointer:selector] forKey:request];
[request startAsynchronous];
但是,它不会返回正确的数据(nil
s 或随机)我尝试从 -requestFinished:
中访问 [_delegate objectForKey:request]
,因此我使用作为临时解决方案:
[_delegates setObject:delegate forKey:[request url]];
[_selectors setObject:[NSValue valueWithPointer:selector] forKey:[request url]];
但是 [request URL]
对于每个单独的请求来说并不是唯一的。我知道要成为可行的密钥,它需要有-hash
和 -isEqual:
返回相同的结果,即如果对象对 -isEqual:
返回 YES
那么它们必须都返回与 -hash
相同。
从 ASIFormDataRequest : ASIHTTPRequest : NSOperation : NSObject
我看不到从 NSObject
重写 -isEqual:
或 -hash
的方法> 和 ASIHTTPRequest
实现 (NSCopying)
协议。
那么什么给出呢?为什么我不能使用请求作为密钥?我可以使用该请求的其他唯一标识符吗?
任何帮助表示赞赏。作为完整参考,我尝试实现一个双层回调,其中 WebServices
类解析 -requestFinished
上的数据(并处理网络错误和重新登录),然后进行另一个回调,以便仅将 JSON 数据作为 NSDictionary
发送。
I'm attempting to use a ASIHTTPRequest/ASIFormDataRequest
as a key in a NSDictionary as so:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:GPUserData.userlogin forKey:@"username"];
[request setPostValue:GPUserData.password forKey:@"password"];
[request setDelegate:self];
[_delegates setObject:delegate forKey:request];
[_selectors setObject:[NSValue valueWithPointer:selector] forKey:request];
[request startAsynchronous];
But, it doesn't return the right data (nil
s or random) when I try to access [_delegate objectForKey:request]
from within -requestFinished:
, so I'm using as a temp solution:
[_delegates setObject:delegate forKey:[request url]];
[_selectors setObject:[NSValue valueWithPointer:selector] forKey:[request url]];
But [request URL]
isn't unique per individual request. I know that for something to be a viable key, it needs to have -hash
and -isEqual:
return the same result, i.e. if the objects return YES
to -isEqual:
then they must both return the same from -hash
.
From ASIFormDataRequest : ASIHTTPRequest : NSOperation : NSObject
I can see no method that overrides -isEqual:
or -hash
from NSObject
and ASIHTTPRequest
implements (NSCopying)
protocol.
So what gives? Why can't I use the request as a key? Is there some other unique identifier for the request that I can use?
Any help is appreciated. For full reference, I'm trying to implement a double-tier callback where the WebServices
class parses the data on -requestFinished
(and handles network errors and re-logins) and then makes another callback so just the JSON data gets sent as a NSDictionary
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将唯一值存储到 request.tag 中,或者使用 userinfo 字典来存储您需要存储的数据吗?例如:
Can you instead store a unique value into request.tag, or use the userinfo dictionary to store the data you need to store? eg: