swiftuiwidgetkit

WidgetKit proper placeholders


I'm having troubles on figuring out proper placeholders for WidgetKit. The issue I'm having is I'm not sure how to set say a default value for Codable data, I attempted but it's not showing any data in my placeholder view. I would like my placeholder to show the Hourly and Daily Codable data but with default values.

Then here's my placeholder in my Widget

func placeholder(in context: Context) -> SimpleEntry {
    SimpleEntry(date: Date(), weather: Weather(current: Current(symbol: "n200", symbolPhrase: "partly cloudy", windSpeed: 0)), hourly: Hourly(forecast: [Hour]()), daily: Daily(forecast: [Day]()))
}
struct Day: Codable {
    let date: String
    let symbol: String
    let symbolPhrase: String
    let maxWindSpeed: Int
    
    enum CodingKeys: String, CodingKey {
        case date, symbol, symbolPhrase, maxWindSpeed
    }
    
    init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        date = try container.decode(String?.self, forKey: .date) ?? "2020-03-16"
        symbol = try container.decode(String?.self, forKey: .symbol) ?? "d320"
        symbolPhrase = try container.decode(String?.self, forKey: .symbolPhrase) ?? "partly cloudy"
        maxWindSpeed = try container.decode(Int?.self, forKey: .maxWindSpeed) ?? 0
    }
}

enter image description here

enter image description here


Solution

  • Easy solution, for some reason it went over my head.

    Array(repeating: Hour(time: "2020-03-16T14:00+01:00", symbol: "n200" , symbolPhrase: "partly cloudy", windSpeed: 0), count: 5) 
    

    enter image description here