【发布时间】:2011-12-19 16:05:19
【问题描述】:
我有一个使用 AFJSONRequestOperation 的函数,我希望仅在成功后返回结果。你能指出我正确的方向吗?我对块和 AFNetworking 还是有点不知所措。
-(id)someFunction{
__block id data;
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id json){
data = json;
return data; // won't work
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
}];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperation: operation];
return data; // will return nil since the block doesn't "lock" the app.
}
【问题讨论】:
标签: ios objective-c-blocks synchronous afnetworking