Skip to content

Commit e786dc4

Browse files
committed
Dispatch error handler on main queue
1 parent fffe1f3 commit e786dc4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

MapboxGeocoder/MBGeocoder.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,14 @@ open class Geocoder: NSObject {
268268
request.setValue(userAgent, forHTTPHeaderField: "User-Agent")
269269
return URLSession.shared.dataTask(with: request) { (data, response, error) in
270270

271-
guard let data = data else {
272-
if let e = error as NSError? {
273-
errorHandler(e)
274-
} else {
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)
271+
guard let data = data else {
272+
DispatchQueue.main.async {
273+
if let e = error as NSError? {
274+
errorHandler(e)
275+
} else {
276+
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"])
277+
errorHandler(unexpectedError)
278+
}
277279
}
278280
return
279281
}

0 commit comments

Comments
 (0)