I'm currently developing an application using SwiftUI
.
If I run the code below, the display result will be A
, But I want to make it the display result B
.
What kind of code can this be achieved?
Here is the code:
struct TestView:View {
let fruits = ["apple","apple","apple","orange","orange","banana"]
@State var tmpFruits = [""]
var body: some View{
List(fruits, id: \.self){fruit in
if tmpFruits.contains(fruit) == false{
Button(action: {
}, label: {
Text(fruit)
})
.onAppear(){
tmpFruits.append(fruit)
}
}
}
}
}
Swift 5.0
SwiftUI 2.0