【发布时间】:2018-03-22 17:26:33
【问题描述】:
func downloadCurrentWeather(completed: @escaping DownloadComplete){
Alamofire.request(API_URL).responseJSON { (response) in
let result = response.result
let json = JSON(result.value) // <-- (EXPRESSION IMPLICITLY COERCED WARNING)
self._cityName = json["name"].stringValue
let tempDate = json["dt"].double
let convertedDate = Date(timeIntervalSince1970: tempDate!)
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .none
let currentDate = dateFormatter.string(from: convertedDate)
self._date = "\(currentDate)"
self._weatherType = json["weather"][0]["main"].stringValue
let downloadedTemp = json["main"]["temp"].double
self._currentTemp = (downloadedTemp! - 273.15).rounded(toPlaces: 0)
completed()
}
}
【问题讨论】:
-
value是可选的,我认为。将let result = ...行替换为guard let result = ... else { ... }语句,指定在result为nil时您希望它执行的操作... -
欢迎来到 StackOverflow!也许您可以添加更多详细信息并展示您自己所做的工作来回答您的问题(例如,您在 Google 上找到了什么,您不了解的内容等等)。阅读How to create a Minimal, Complete, and Verifiable example 了解更多信息。