Here's the model of the API that I'm using
// MARK: - Welcome
struct NOAAWeatherDecoder: Codable, Identifiable {
var id = UUID()
let type: String
let geometry: Geometry
let properties: Properties
enum CodingKeys: String, CodingKey {
case type, geometry, properties
}
}
// MARK: - Properties
struct Properties: Codable {
let updated: Date
let units, forecastGenerator: String
let generatedAt, updateTime: Date
let validTimes: String
let elevation: Elevation
let periods: [Period]
}
// MARK: - Elevation
struct Elevation: Codable {
let value: Double
let unitCode: String
}
// MARK: - Period
struct Period: Codable {
let number: Int
let name: String
let startTime, endTime: Date
let isDaytime: Bool
let temperature: Int
let temperatureUnit: TemperatureUnit
let temperatureTrend: JSONNull?
let windSpeed, windDirection: String
let icon: String
let shortForecast, detailedForecast: String
}
I am able to get upto periods, but nothing after that. Here's the part of the code where I'm running into the issue
ForEach(noaaWeatherData.weathernoaadata) { day in Text(day.properties.periods[0]) After this I'm not entirely sure. }
Thanks!
-
—
workingdogintokyo
Add a CommentNot sure what you really mean with "I am able to get upto periods, but nothing after that." My guess is, you want to access the parameters of the period. If so, then try this:
Text(day.properties.periods[0].name) Text(String(day.properties.periods[0].temperature))In swift, it is fundamental to understand this.