如何从函数中的URLSession返回响应? 以下是我到目前为止所写的内容:
func getPointElevation(lat: Double, lon: Double, useBing: Bool = false)->Any{
let url=URL(string: "https://api.open-elevation.com/api/v1/lookup?locations\(String(lat)),\(String(lon))")
let d:Data
struct DatiPunto: Codable{
var result: [String: [[String: Double]]]
}
let task = URLSession.shared.dataTask(with: url!) { (data, response, error) in
d=data!
}
task.resume()
let decoder = JSONDecoder()
do{
return try decoder.decode(DatiPunto.self, from: d)
}catch{
}
}