Swift4:从函数返回HTTP响应

时间:2018-06-26 07:49:21

标签: swift

如何从函数中的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{

    }
}

0 个答案:

没有答案