I'm trying to parse a location (CLLocation) into a String.
func locationToString (currentLocation: CLLocation) -> String? {
var whatToReturn: String?
CLGeocoder().reverseGeocodeLocation(currentLocation, completionHandler: { (placemarks: [AnyObject]!, error: NSError!) in
if error == nil && placemarks.count > 0 {
let location = placemarks[0] as CLPlacemark
whatToReturn = "\(self.validateString(location.locality)) \(self.validateString(location.thoroughfare)) \(self.validateString(location.subThoroughfare))"
}
})
return whatToReturn
}
Obviously, whatToReturn always returns null, because completionHandler runs in the background. I'm having a hard time understanding how do I update my String when completionHandler finishes?
Thanks.
Aucun commentaire:
Enregistrer un commentaire