gpt4 book ai didi

swift - 阿拉莫菲尔 4 请求开放天气

转载 作者:行者123 更新时间:2023-11-30 11:38:24 25 4
gpt4 key购买 nike

正在处理我的第一个 Alamofire 请求和更新到 Alamofire 4 的代码。无法正确更新此 Alamofire.request .responseJSON。我正在查看迁移 documentation : 但不够聪明。有什么建议吗?

    let APIKey = "myAPIkey"

func retrieveCurrentWeatherAtLat(lat: CLLocationDegrees, lon: CLLocationDegrees,
block: (_ weatherCondition: WeatherCondition) -> Void) {
let url = "http://api.openweathermap.org/data/2.5/weather?APPID=\(APIKey)"
let params = ["lat": lat, "lon": lon]

// Send the request
Alamofire.request(url, method: .get, parameters: params)
.responseJSON { request, response, result in
switch result {
case .Success(let json):
let json = JSON(json)
block(weatherCondition: self.createWeatherConditionFronJson(json))
case .Failure(_, let error):
print("Error: \(error)")
}
}
}

最佳答案

也许可以帮到你

    Alamofire.request(url, method: .get, parameters: params, encoding: JSONEncoding.default).responseJSON { (response) in

switch response.result {
case .Success(let json):
let json = JSON(json)
block(weatherCondition: self.createWeatherConditionFronJson(json))
case .Failure(_, let error):
print("Error: \(error)")
}
}

关于swift - 阿拉莫菲尔 4 请求开放天气,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49481754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com