EDIT: Disregard. It was an asynchronous operation that ran in the background. The result is returned from the Block just fine. I was NSLog'ing the results before the data was returned which is why I had the problem.
I spent this morning using the CLLocation to try and get a zip code for the area a phone is in. The method works and I can see the zip code when using breakpoints. But for the life of me I can't figure out how to get data out of the block when it finishes? The block runs asynchronous, so off the main thread.
I am trying to get the returned results out of the block to use else where. I first tried a global ivar but the results were NULL.
The reverseGeocodeLocation: Method returns void so I have no idea how to return this data. I don't really understand blocks so any help would be appreciated in retrieving the data.
I spent this morning using the CLLocation to try and get a zip code for the area a phone is in. The method works and I can see the zip code when using breakpoints. But for the life of me I can't figure out how to get data out of the block when it finishes? The block runs asynchronous, so off the main thread.
I am trying to get the returned results out of the block to use else where. I first tried a global ivar but the results were NULL.
The reverseGeocodeLocation: Method returns void so I have no idea how to return this data. I don't really understand blocks so any help would be appreciated in retrieving the data.
Code:
- (void)reverseGeocodeLocation:(CLLocation *)location{
CLGeocoder* reverseGeocoder = [[CLGeocoder alloc] init];
if (reverseGeocoder) {
[reverseGeocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark* placemark = [placemarks firstObject];
if (placemark) {
//Using blocks, get zip code
NSString *zip = [placemark.addressDictionary objectForKey:(NSString*)kABPersonAddressZIPKey];
}
}];
}
}
Last edited: