From c3c2d4f6bb5de0aee659150693e471afe1f8d2ff Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 31 Aug 2018 09:56:40 -0700 Subject: [PATCH] Reorder failure errors (#10) When there are no locations found for a query, MapKit returns a NSError instead of an empty array. This resulted in us printing a opaque error. Now we'll do that last, only if there is an error, but we also found a place. Here's an example of a query that currently fails: Lyft HQ San Francisco --- sources/query.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sources/query.swift b/sources/query.swift index 4f7f805..236c448 100644 --- a/sources/query.swift +++ b/sources/query.swift @@ -14,10 +14,6 @@ func findLocation(from arguments: [String]) -> Result { let search = MKLocalSearch(request: request) let (response, error) = search.perform() - if let error = error { - return .failure(error.localizedDescription) - } - guard let placemark = response?.mapItems.first?.placemark else { return .failure("No locations found for '\(query)'") } @@ -26,6 +22,10 @@ func findLocation(from arguments: [String]) -> Result { return .failure("No coordinate found for '\(placemark.name ?? "")'") } + if let error = error { + return .failure(error.localizedDescription) + } + return .success(coordinate) }