I'm working with WeatherKit which has a struct called WeatherAlert. WeatherAlert has an init method that requires a Decoder:
/// - Parameter decoder: The decoder to read data from.
public init(from decoder: Decoder) throws
I'd like to create an example WeatherAlert to use in a view preview. But I'm at a loss for how to create an object using the method above. How can I create an example WeatherKit object for use in my preview?
#Preview {
//??
let testAlert: WeatherAlert = WeatherAlert(from: ??)
AlertView(alert: testAlert)
}
You can get a JSON from
WeatherKitsinceWeatherAlertisCodableOnce you have a JSON you can put it in a
.jsonfile and load it when you need it.The code will look something like
The trick with
alertis that you need to get a sample JSON from a place that currently has alerts. So it might help to look at a place on the weather map and use that location.