Inside the following function, I've used a block. But when I call this function, it is returned even before the block is executed. I understood that Block inturn uses the threads and executes separately so that the function doesnt wait for it to return. But, Is there any other way I could make the function execution wait, or any other way to achieve the functionality of this block without using the block itself ?
-(int)findCurrentZip
{
CLLocation *userLocation = [[CLLocation alloc] initWithLatitude:[self findCurrentLatitude]
longitude:[self findCurrentLongitude]];
int zipcode;
self.myGeocoder = [[CLGeocoder alloc] init];
[self.myGeocoder
reverseGeocodeLocation:userLocation
completionHandler: (id)^(NSArray *placemarks, NSError *error) {
if (error == nil && [placemarks count] > 0)
{
NSLog(@"Placemarks: %@",placemarks);
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"Country = %@", placemark.country);
NSLog(@"Postal Code = %@", placemark.postalCode);
zipcode = (int)placemark.postalCode;
NSLog(@"Locality = %@", placemark.locality);
NSLog(@"Country%@",[placemarks lastObject]);
}
else if (error == nil && [placemarks count] == 0)
{
NSLog(@"No results were returned.");
}
else if (error != nil)
{
}
}];
return zipcode;
}