I am new to Swift programming. I am trying to change the content of each text and the colours with onHover as follows.
@State var isHover = false
@State var text = "OUT"
...
let textlist = [text, text]
VStack {
ForEach(0 ..< textlist.count, id: \.self){ index in
Text(textlist[index])
.foregroundColor(self.isHover ? Color.yellow : Color.white)
.onHover(perform: { flag in
self.isHover = flag
if flag {
self.text = "IN"
}else{
self.text = "OUT"
}
})
}
}
The result was that the contents of both were changed to "IN" from "OUT" and the colours yellow on a mouse over. I just want to change each which a mouse is over. How can I fix this problem? Thank you.