場所 (CLLocation) を文字列に解析しようとしています。
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 = "\(location.locality) \(location.thoroughfare) \(location.subThoroughfare)"
}
})
return whatToReturn
}
明らかに、completeHandler はバックグラウンドで実行されるため、whatToReturn は常に null を返します。completionHandler が終了したときに String を更新する方法を理解するのに苦労していますか?
ありがとう。