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!
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
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)
}
}
}
I have a userDefault using Appstorage and would like to have a function access that value to use in a switch. What would be the best approach to accomplish this?