__block 块运行后变量返回 nil

__block variable returning nil after block runs

我创建了一个字符串,并在其前面加上了 __block 标识符,这样我就可以在我的块之外访问该变量。但是,一旦我尝试 运行 应用程序变量 returns 'nil':

-(void)downloadParcelData {
    __block NSString *test;

    MKMapRect mRect = self.mapView.visibleMapRect;
    NSArray *array = [NSArray array];
    array = [self getBoundingBox:mRect];

    NSString *polygonString = [self convertCoordinates:array];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = nil;

    NSDictionary *parameters = @{@"client" : @"xxxxxxxxxx",
                             @"spatial_intersect" : [NSString    stringWithFormat:@"POLYGON((%@))", [polygonString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]]};

    [manager GET:@"someURL" parameters:parameters progress:nil success:^(NSURLSessionTask *task, id responseObject) {
        NSLog(@"JSON: %@", responseObject);
        test = responseObject[@"txn_id"];
     } failure:^(NSURLSessionTask *operation, NSError *error) {
        NSLog(@"Error: %@", error);
     }];

    [self fetchParcelData:test];

}

关于为什么会发生这种情况有什么想法吗?提前致谢。

[manager GET:parameters:progress:success:failure] 似乎是一种异步方法。那条线不会阻塞;执行立即继续到 [self fetchParcelData:]。成功块是您应该放置要处理对 GET 请求的响应的代码的地方。