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.

Accepted Reply

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)")
}
Add a Comment

Replies

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)")
}
Add a Comment