I'm trying to get the coordinates of an address passed from one view controller to another via a segue. The geocoding function to get the coordinates runs asynchronously, so I'm using a completion block to capture the coordinate values.
EDIT: The function below is triggered by clicking a button-
func getCoordinates(completion: (coordinates)) -> () {
geocoder.geocodeAddressString(address) { (placemarks, error) -> Void in
if((error) != nil) {
print("Error", error)
}
if let placemark = placemarks?.first {
let coordinates: CLLocationCoordinate2D = placemark.location!.coordinate
completion(coordinates)
}
}
}
What I'm trying to do is pass the coordinates to the next view controller AFTER they've been obtained. I suspect I can do this with prepareForSegue and GCD but I could be wrong....
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showCoordinates" {
if let nextVC = segue.destinationViewController as? NextViewController {
// What goes here?
}
}
}
Could use some help/suggestions. Thanks in advance.