Swiftui阵列带OpenWeatherMap

发布于 2025-02-05 15:19:38 字数 520 浏览 1 评论 0原文

我在SwiftUI天气应用程序中进行了小时的预测,但是在我的结构中,它需要一个天气每小时数据的阵列。早些时候它符合字符串。我使其符合数组,但我得到了错误对通用类型“数组”的引用需要< ...>中的参数。

struct:

struct OneCall: Decodable {
    let lat, lon: Double
    let timezone : String
    let timezone_offset : Int
    let current: CurrentResponse
    let hourly: HourlyResponse

    struct HourlyResponse: Decodable{
        var hourly: Array //Error
    }
}

我尝试使用<任何>,但无效的

帮助将不胜感激

I have hourly forecast in my SwiftUI Weather App but in my struct, it needs an array for the weather hourly data. Earlier it was conformed to string. I made it conform to array but I get the error Reference to generic type 'Array' requires arguments in <...>.

Struct:

struct OneCall: Decodable {
    let lat, lon: Double
    let timezone : String
    let timezone_offset : Int
    let current: CurrentResponse
    let hourly: HourlyResponse

    struct HourlyResponse: Decodable{
        var hourly: Array //Error
    }
}

I've tried using <Any> but that didn't work

Help would be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

油饼 2025-02-12 15:19:38

小时的值实际上是currentResponse struct MINUS MINUS SunriseSunset的数组。

如果您使用这些使其可选

let sunrise: Date?
let sunset: Date?

,并在 onecall 中声明hourly

let hourly: [CurrentResponse]

,或者对于错误消息而言,此语法

let hourly: Array<CurrentResponse>

不需要hourlylysponse struct。


任何完全不支持Codable

The value for hourly is actually an array of the CurrentResponse struct minus the keys sunrise and sunset.

If you use those make them optional

let sunrise: Date?
let sunset: Date?

and declare hourly in OneCall

let hourly: [CurrentResponse]

or this syntax with regard to the error message

let hourly: Array<CurrentResponse>

the HourlyResponse struct is not needed.


Any is not supported by Codable at all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文