I keep getting the “Cannot convert value of type ‘Bool’ to expected argument type ‘Binding'” error and I’m not too sure on how to fix it.
This is the code where the error appears in ContentView:
@State private var habitEggs: [HabitEggButton] = [
HabitEggButton(habitName: "Drink Water", display: true),
HabitEggButton(habitName: "Gym", display: true),
HabitEggButton(habitName: "Read a Book", display: true)
]
And this is the code where that defines my HabitEggButton struct:
import Foundation
import SwiftUI
struct HabitEggButton: View, Identifiable {
let id = UUID()
var habitName: String
@Binding var display: Bool
var body: some View {
Button(action: {
print(habitName + " button tapped")
if display {
print("Yes")
}
else {
print("No")
}
}) {
Image("egg_uncracked")
.resizable()
.frame(width: 120, height: 120)
}
.supportsLongPress {
display = false
print(habitName + " button held")
}
}
}
Setting it as .constant(true) seems to fix the problem, but I want the value to be mutable. My goal is for the button to disappear once it is held, where it would rerender the HabitEggs through the array again with the eggs gone after display is set to false.