【问题标题】:How I can fix Extra Argument In call?如何修复通话中的额外参数?
【发布时间】:2020-12-07 12:21:20
【问题描述】:

我正在用 Swift 编写 WeatherApp。我对称为“调用中的额外参数”的编译有问题。 我正在写 HourlyForecast,你可以在那里看到我的代码:

视图控制器:

HourlyForecast.downloadDailyForecastWeather { (hourlyForecastArray) in
    for data in hourlyForecastArray {
        print("forecast data: \(data.temp, data.date)")
    }
} 

HourlyForecast.swift 的一部分:

init(weatherDictionary: Dictionary<String, AnyObject>) {
    let json = JSON(weatherDictionary)
    self._temp = json["temp"].double
    self._date = currentDateFromUnix(unixDate: json["ts"].double!)
    self._weatherIcon = json["weather"]["icon"].stringValue
}

我该如何解决?

【问题讨论】:

  • 你指的是什么方法调用?另一方面,我建议您查看Codable 协议

标签: json swift weather


【解决方案1】:

您必须插入每个变量分别

for data in hourlyForecastArray {
    print("forecast data: \(data.temp), \(data.date)") 
}

注意事项:

  • 不要使用带有前导下划线的 objective-c-ish 变量名。
  • 在 Swift JSON 字典中,值是 Any 而不是 AnyObject
  • 使用Codable,它比SwiftyJSON 高效得多。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-17
    相关资源
    最近更新 更多