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

时间:2012-03-16 07:15:41

标签: iphone objective-c ios scope block

这可能听起来像一个新手问题,但我是iOS开发新手。

arg1arg2completionHandler块中是否可见,代码如下?如果不是将这些变量传递给块的正确方法是什么?

- (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];
     }];
}

1 个答案:

答案 0 :(得分:0)

是的,只需使用它们。阅读更多关于块的信息: http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/Blocks/Articles/bxVariables.html

(这是积木的一大优势 - 你几乎留在你周围的范围内)

相关问题