Why do I get a EXC_BAD_INSTRUCTION
with just an empty call to geocodeAddressString
:
geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [CLPlacemark]?, error: NSError?) -> Void in
} as! CLGeocodeCompletionHandler)
Why do I get a EXC_BAD_INSTRUCTION
with just an empty call to geocodeAddressString
:
geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [CLPlacemark]?, error: NSError?) -> Void in
} as! CLGeocodeCompletionHandler)
The issue in your case is that error
is an Error?
reference in Swift 3, no longer a NSError?
. Thus your forced cast is failing. You can fix that like so:
geocoder.geocodeAddressString(address, completionHandler: {(placemarks: [CLPlacemark]?, error: Error?) -> Void in
} as! CLGeocodeCompletionHandler)
But that as! CLGeocodeCompletionHandler
is not needed. If it suggested that cast, it probably only did so because it noticed that your closure was not of the right type.
Frankly, even easier, just let it infer the right types and you don't have to worry about this sort of issue:
geocoder.geocodeAddressString(address) { placemarks, error in
}