Created
September 5, 2018 18:16
-
-
Save davidseek/0bd22ff6134fa5f920e875703f2279d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MARK: - Get Location | |
| extension LocationManager { | |
| func getLocation(forPlaceCalled name: String, | |
| completion: @escaping(CLLocation?) -> Void) { | |
| let geocoder = CLGeocoder() | |
| geocoder.geocodeAddressString(name) { placemarks, error in | |
| guard error == nil else { | |
| print("*** Error in \(#function): \(error!.localizedDescription)") | |
| completion(nil) | |
| return | |
| } | |
| guard let placemark = placemarks?[0] else { | |
| print("*** Error in \(#function): placemark is nil") | |
| completion(nil) | |
| return | |
| } | |
| guard let location = placemark.location else { | |
| print("*** Error in \(#function): placemark is nil") | |
| completion(nil) | |
| return | |
| } | |
| completion(location) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment