Search code examples
swiftuiopenweathermap

OpenWeatherMap API hourly forecast unavailable


In my weather app, I call the weather forecast in a text field but I get the error: No exact matches in call to initializer.

Here is the code that might be related:

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>
    }

Solution

  • It should definitely be not an array in Text(). It is not clear what's type of .hourly, but it should be something like

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