Skip to content

Commit d341179

Browse files
beforeoldfrederoni
authored andcommitted
another way to cast the error
1 parent bc74c10 commit d341179

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

MapboxGeocoder/MBGeocoder.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,11 @@ open class Geocoder: NSObject {
269269
return URLSession.shared.dataTask(with: request) { (data, response, error) in
270270

271271
guard let data = data else {
272-
if let error = error as? NSError {
273-
errorHandler(error)
272+
if let e = error as NSError? {
273+
errorHandler(e)
274274
} else {
275-
errorHandler(NSError(domain: MBGeocoderErrorDomain, code: -1024, userInfo: [NSLocalizedDescriptionKey : "unexpected error", NSDebugDescriptionErrorKey : "this error happens when data task return nil data and nil error, which typically is not possible"]))
275+
let unexpectedError = NSError(domain: MBGeocoderErrorDomain, code: -1024, userInfo: [NSLocalizedDescriptionKey : "unexpected error", NSDebugDescriptionErrorKey : "this error happens when data task return nil data and nil error, which typically is not possible"])
276+
errorHandler(unexpectedError)
276277
}
277278
return
278279
}

0 commit comments

Comments
 (0)