- 一个GET请求(AFNetworking)
- 分配给请求成功
- 使用变量一旦请求完成内部变量初始化变量之前
我得到的错误:
- 当试图GET请求之后做一些变量,它打破了,自称有给变量没有值尚未
以下是我的代码,我该如何解决这个问题问题?
- (IBAction)synchronisePressed {
//Would like to initialise a variable here
__block NSArray *received;
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://foo.com/foo/"
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
//Assign responseObject to received object
received = responseObject;
NSLog(@"Woo: %@", @"got here");
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
//Now outside of request, so use array in some way
[foo received];
}
[Objective-C的块和变量的作用域(可能重复http://stackoverflow.com/questions/9407675/objective-c-blocks-and-variable-scope) – Larme