私はこの方法を持っている:メソッドからクロージャを使用してデータを返すにはどうすればよいですか?
internal func getCoordinate(addressString : String,
completionHandler: @escaping(CLLocationCoordinate2D, NSError?) -> Void) {
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(addressString) { (placemarks, error) in
if error == nil {
if let placemark = placemarks?[0] {
let location = placemark.location!
completionHandler(location.coordinate, nil)
return
}
}
completionHandler(kCLLocationCoordinate2DInvalid, error as NSError?)
}
}
が好き、それを使用します。
self.getCoordinate(addressString: "Summerville, SC", completionHandler: <#T##(CLLocationCoordinate2D, NSError?) -> Void#>)
しかし、私はこのような何かをしたい:
let currentLocation = self.getCoordinate(addressString: "Summerville, SC", completionHandler: <#T##(CLLocationCoordinate2D, NSError?) -> Void#>)
はどのように私はそれを行うのですか?