我试图从Apple的WeatherKit获取最低和最高温度,以使我的天气应用程序变得复杂,但Apple的开发人员文档没有显示如何获取该值,并且以前没有人问过这个问题。
这是我尝试过但不起作用的代码:
Text("L: \(weather.currentWeather.lowTemperature) H: \(weather.currentWeather.highTemperature)")
// Text("L: \(Minimum Temperature) H: \(Maximum Temperature)")
您可以通过
DayWeather
获得它
https://developer.apple.com/documentation/weatherkit/dayweather
var highTemperature: Measurement<UnitTemperature>
var lowTemperature: Measurement<UnitTemperature>
您可以通过
.daily
获得它
let daily = try await service.weather(for: newYork, including: .daily)
https://developer.apple.com/documentation/weatherkit/weatherquery
尝试使用[DayWeather]
更新后的代码将是: Text("L: (weather.dailyForecase[0].lowTemperature) H: (weather.dailyForecast[0].highTemperature)")
这里 [0] 是 DayWeather 中数组项的第一个索引