This may sound a newbie question, however I’m new to iOS dev.
Are the arg1 and arg2 visible in completionHandler block, in following code ? If not what is the correct way to pass those variables to the block ?
- (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];
}];
}
Yes just use them. Read more about blocks here:
http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/Blocks/Articles/bxVariables.html
(that is one big advantage of blocks – your nearly stay in your surrounding scope)