I worked out a way to get around it using JSON encoding / decoding. I noted that a JSONEncoder and JSONDecoder DID encode/decode the undocumented struct properties that the Xcode compiler does not recognise. (Why? How?) I created a custom struct to decode back into with all the properties of the new WeatherKit.WeatherAlert structure. The new properties are now available to use on the MyWeatherAlertObject.
I chose to guard whether onsetTime and endDate were non-nil, so I can trigger a WeatherKit REST API lookup for these alerts, as that also returns all the properties.
@available(iOS 16.0, *)
struct MyWeatherAlertObject: Codable {
var detailsURL: URL
var source: String
var date: Date
var expirationDate: Date
var issuedDate: Date
var onsetTime: Date?
var endDate: Date?
var summary: String
var description: String
var details: URL?
var region: String?
var severity: WeatherKit.WeatherSeverity
var importance: String
var metadata: WeatherKit.WeatherMetadata
var id: UUID
init?(fromWeatherAlert alert: WeatherAlert?) {
guard let alert = alert,
let data = try? JSONEncoder().encode(alert),
let obj = try? JSONDecoder().decode(MyWeatherAlertObject.self, from: data),
// no point using if these two are missing
obj.onsetTime != nil && obj.endDate != nil
else { return nil }
self = obj
}
}