so here is the problem. my code runs fine when i give values within the file. However, i made a separate model file from which i want to iterate through an Array of WeatherDay objects to print them to make them dynamic. However, logically it sounds easy but i run into these annoying error which wont let me compile. anyone help!! Code given below :
struct ContentView: View {
@State private var isNight = false
var body: some View {
ZStack {
var selectedWeather = getWeatherValues()
// binding basically enforces that the value for the object stays the same
BackgroundView(isNight: $isNight)
VStack {
let days = selectedWeather.getWeatherDayListData()
CityTextView(cityName: selectedWeather.getCity())
// first object
mainWeatherView(isNight: $isNight, todayWeather:
selectedWeather.getWeatherDayListData()[0])
HStack(spacing: 20) {
weatherDayView(weatherDays: selectedWeather.getWeatherDayListData())
}
}
Spacer() //basically used to move the text to the top of the frame
Button {
isNight.toggle()
} label: {
WeatherButton(title: "Change Day Time",
textColor: .blue,
backgroundColor: .white)
}
Spacer()
}
}
}
struct weatherDayView: View {
//this is where i get all the errors like
//closure expression is unused
//expected { in struct
//expressions are not allowed at the top level.
@State var weatherDays: [WeatherDay]
var body: some View {
ForEach(weatherDays, id: \.self) { singleDay in
VStack {
Text(singleDay.dayOfWeek)
.font(.system(size: 18, weight: .medium, design: .default))
.foregroundColor(.white)
Image(systemName: singleDay.ImageName)
.renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 40, height: 40)
Text("\(singleDay.temperature)°")
.font(.system(size: 28, weight: .medium))
.foregroundColor(.white)
}
}
}
}