Post

Replies

Boosts

Views

Activity

How can I go about accessing the Periods portion of NOAA Api response?
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!
1
0
795
Sep ’21
ObservableObject Array data not updating
I have two views where I'm trying to get View 2 to run the function in the Observable object and\or update an array so far I've not been able to get it to run or update the array. I'm still learning how to work with ObservableObjects. Thanks! View1.swift:   @Published var arrayInt = [6, 6.5]   @Published var fooString = "Name"   func appendToArray() {     fooString = "Boom, updated!" arrayInt.append(11)   } }  struct GraphView: View { @StateObject var graph = graphData()    var body: some View { .... some data    } } View2.swift: struct DetailView: View { @StateObject var graph = graphData()    var body: some View { ....Some data        .onAppear{           graph.appendToArray() graph.arrayInt.append(11)         }    } }
2
0
3.3k
Aug ’21