I'm trying to create a simple app that keeps count of how buttons in a list of clothing items have received more than 5 taps.
I've tried using the code below, but keep getting the error "Cannot convert value of type 'ContentView.clothing' to expected argument type 'Int'" in the line if clothes[i].taps >= 5.
I feel like somehow this might be related to the fact that I've tried to pass a whole struct as a parameter of the func. Perhaps I'm not meant to do this?
Any guidance much appreciated!
import SwiftUI
struct ContentView: View {
struct clothing {
var type: String
var taps: Int
}
@State var currentClothes = [
clothing(type: "tshirt", taps: 0),
clothing(type: "dress", taps: 0)
]
var body: some View {
NavigationView{
List{
ForEach(0..<currentClothes.count) { i in
Button("\(currentClothes[i].type)") {
self.currentClothes[i].taps += 1
print(currentClothes)
}
}
}
Text("\(tapCount(clothes: currentClothes))")
}
}
func tapCount(clothes: [clothing]) -> Int {
var total = 0
for i in clothes {
if clothes[i].taps >= 5
{total += 1}
}
return total
}
}