Hi there!
I am relatively new to Swift. I want to accomplish that the first item of the weatherList is displayed with a different View.
Unfortunately I get this error in those 2 Lines (VStack and at ForEach-Line). If i put away the if i = 1 then and just use for normal layout for all listitems there is no error.
ERROR: Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols
Here is my code:
var body: some View {
NavigationView {
VStack { // here first error
if self.model.error != nil {
Text(self.model.error!)
}
ForEach(0..<self.model.weatherList.count, id: \.self) { i in // here second error
if i == 1 {
NavigationLink(destination: DetailView(model: self.model.weatherList[i])) {
RowView(model: self.model.weatherList[i])
}
}
else{
NavigationLink(destination: DetailView(model: self.model.weatherList[i])) {
RowView(model: self.model.weatherList[i])
}
}
}
}
.navigationBarTitle(Text("Weather in " + UserSettings.instance.locationSetting))
.navigationBarItems(trailing:
Button(action: {
self.model.reload()
}) {
Image(systemName: "arrow.clockwise")
}
.disabled(model.reloading)
)
}
}
Would appreciate each advice. Thanks.