Skip to content

Instantly share code, notes, and snippets.

@davidseek
Created September 5, 2018 18:01
Show Gist options
  • Select an option

  • Save davidseek/3b4916f36eb9b260e40c773ca4bd4275 to your computer and use it in GitHub Desktop.

Select an option

Save davidseek/3b4916f36eb9b260e40c773ca4bd4275 to your computer and use it in GitHub Desktop.
class ViewController: UIViewController {
// - Outlets
@IBOutlet weak var locationLabel: UILabel!
// - Constants
private let locationManager = LocationManager()
override func viewDidLoad() {
super.viewDidLoad()
guard let exposedLocation = self.locationManager.exposedLocation else {
print("*** Error in \(#function): exposedLocation is nil")
return
}
self.locationManager.getPlace(for: exposedLocation) { placemark in
guard let placemark = placemark else { return }
var output = "Our location is:"
if let country = placemark.country {
output = output + "\n\(country)"
}
if let state = placemark.administrativeArea {
output = output + "\n\(state)"
}
if let town = placemark.locality {
output = output + "\n\(town)"
}
self.locationLabel.text = output
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment