代码之家  ›  专栏  ›  技术社区  ›  Chocord Coder

OpenWeatherMap API小时预测不可用

  •  1
  • Chocord Coder  · 技术社区  · 2 年前

    在我的天气应用程序中,我在文本字段中调用天气预报,但出现错误: No exact matches in call to initializer .

    以下是可能相关的代码:

    ScrollView(.horizontal){
        HStack(spacing: 5.0) {
            ForEach(0..<25) {_ in
                VStack{
                    Text([weather.hourly.hourly]) //Error
                        .bold()
                        .font(.subheadline)
                        .frame(width: 105, height: 15)
                }
            }
        }
    }
    
    struct OneCall: Decodable {
        let lat, lon: Double
        let timezone : String
        let timezone_offset : Int
        let current: CurrentResponse
        let hourly: HourlyResponse
        struct HourlyResponse: Decodable{
            let sunrise: Date?
            let sunset: Date?
            var hourly: Array<CurrentResponse>
        }
    
    1 回复  |  直到 2 年前
        1
  •  1
  •   Asperi    2 年前

    它绝对不应该是中的数组 Text() . 不清楚是什么类型的 .hourly ,但应该是这样的

    Text("\(weather.hourly.hourly)")