Search code examples
objective-cclgeocoder

Unable to get postal code from CLGeocoder


i am trying to get postal code from CLGeocoder but app is crashing with error *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument'

here is my code

CLPlacemark *placemark = [placemarks objectAtIndex:0];
             NSString *Postalcode = [[NSString alloc]initWithString:placemark.postalCode];
             NSLog(@"Postal : %@",Postalcode);

output is "null"


Solution

  • You should check placemark.postalCode before you pass to init for NSString Check if it is nil.