Hi! I am trying to add some logic in ForEach to compute the views, but XCode does not allow that. Can you tell me why?
ForEach(0...10, id: \.self, content: {
i in
let s : Int = i
return Text("abc")
}
XCode will return error message for the above coce: Cannot convert value of type '(_) -> _' to expected argument type '(_.Element) -> _'
However, the code below will work:
ForEach(0...10, id: \.self, content: {
i in
return Text("abc")
}
I looked at the declaration of ForEach, but couldn't find why it doesn't accept the "let" statement.
init(_ data: Data, @ViewBuilder content: @escaping (Data.Element) -> Content)
I understand that if I put the logic in a separate structure view for each cell, I can get the code work, but just trying to get a better understanding on SwiftUI and posted this question.
Thank you!