- 一個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