0

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"

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Vix Hunk
  • 303
  • 4
  • 17
  • Possible duplicate of [CLPlacemark crash in Swift](https://stackoverflow.com/questions/27671435/clplacemark-crash-in-swift) – trungduc Mar 13 '19 at 05:09

1 Answers1

0

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

flyingBear
  • 487
  • 1
  • 6
  • 16