I'd like to ask you a question about the usage of mathematical operations inside the view.
struct MyMenu: View {
var cnt: Int = 0
let colors: [Color] = [.red, .green, .blue]
var body: some View {
ForEach(colors, id: \.self) { color in
Text(color.description)
.padding()
.background(color)
cnt += 1
}
}
}
It gives me an error:
Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols
I do not understand what's wrong with SWIFTUI syntax? Why simple mathematical operations cannot be used inside the some View.
Any solution? Thank you!