I have following function geocoding address from GPS coordinates
private func getAddressFromLocation(forLocation: CLLocationCoordinate2D) {
let geoCoder = CLGeocoder()
geoCoder.reverseGeocodeLocation(CLLocation(latitude: forLocation.latitude, longitude: forLocation.longitude), completionHandler: {(places, error) in
guard error == nil else {
return
}
let place: CLPlacemark = places!.first!
var address: [String] = []
if place.country != nil { address.append(place.country!) }
if place.postalCode != nil { address.append(place.postalCode!) }
if place.locality != nil { address.append(place.locality!) }
if place.thoroughfare != nil { address.append(place.thoroughfare!) }
self.fullAddress = address.joined(separator: ",")
})
}
Function is called from another part of my application and I'm wondering how to ensure that program will wait until fullAddress variable got value (function finish). I tried to put function call into sync dispatch queue but it didn't help. Thanks for any suggestion.