why do I get this error

I get this type of error when I write any iteration statements. the NavigationView and scrollview braces are closed below.

Answered by robnotyou in 702158022

The error message should be self explanatory?
In SwiftUI, you can not just write arbitrary code, when a View is expected.
Remember that you are declaring a UI.

Try replacing your "for" loop with this SwiftUI code:

ForEach(cities, id: \.self) { city in
    Text("City: \(city)")
}
Accepted Answer

The error message should be self explanatory?
In SwiftUI, you can not just write arbitrary code, when a View is expected.
Remember that you are declaring a UI.

Try replacing your "for" loop with this SwiftUI code:

ForEach(cities, id: \.self) { city in
    Text("City: \(city)")
}
why do I get this error
 
 
Q