块处理程序中变量的可见性(范围)



这听起来可能是个新手问题,但我是iOS开发人员的新手。

arg1arg2在以下代码中的completionHandler块中可见吗?如果不是,将这些变量传递到块的正确方法是什么?

- (void)addCurrentLocationNameToDB:(CLLocation *)location param1:(NSString*)arg1 param2:(NSString*)arg2 
{
     CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
     [geoCoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) 
     {
             [self locationNameDidReceive:locationName forLocation:location forTrip:arg1 waypoint:arg2];
     }];
}

是的,只需使用它们。点击此处了解更多关于区块的信息:http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/Blocks/Articles/bxVariables.html

(这是区块的一大优势-你几乎停留在周围的范围内)

最新更新