I'm using CoreLocation to successfully determine the user's location. However when i try to use the CLLocationManagerDelegate method:
func locationManager(_ manager: CLLocationManager!, didFailWithError error: NSError!)
I run into problems with the error term.
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
println("didFailWithError \(error)")
if let err = error {
if err.code == kCLErrorLocationUnknown {
return
}
}
}
This results in a 'Use of unresolved identifier kCLErrorLocationUnknown' error message. I know that the kCLErrors are enums and that they have evolved in Swift but I'm stuck.
Update for Swift 4: The error is now passed to the callback as
error: Errorwhich can be cast to anCLError:Older answer: The Core Location error codes are defined as
and to compare the enumeration value with the integer
err.code,toRaw()can be used:Alternatively, you can create a
CLErrorfrom the error code and check that for the possible values:UPDATE: In Xcode 6.1 beta 2, the
fromRaw()andtoRaw()methods have been replaced by aninit?(rawValue:)initializer and arawValueproperty, respectively: