如何管理在循环中调用异步块?
我的代码被称为 n 次:
- (void) convertToCountries:(NSString*)time longitude:(NSString*)lon latitude:(NSString*)lat {
CLLocation *myLocation = [[CLLocation alloc] initWithLatitude:[lat doubleValue] longitude:[lon doubleValue]];
[geocoder reverseGeocodeLocation:myLocation
completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
if(placemarks && placemarks.count > 0)
{
//do something
CLPlacemark *topResult = [placemarks objectAtIndex:0];
NSString *addressTxt = [NSString stringWithFormat:@"%@, %@ %@,%@ %@", [topResult country],
[topResult subThoroughfare],[topResult thoroughfare],
[topResult locality], [topResult administrativeArea]];
NSLog(@"%@",addressTxt);
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd"];
//Optionally for time zone converstions
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"..."]];
[DataOperations saveRecord:[topResult country] time:time];
}
}];
}
我需要从这些调用中收集输出数据。
任何帮助将不胜感激。