I am running into an issue where two distinct bool bindings are both being toggled when I toggle only one of them. My component looks like
VStack {
Checkbox(label: "Checkbox 1", isOn: $stateVar1)
Checkbox(label: "Checkbox 2", isOn: $stateVar2)
}
where my CheckBox component looks like
struct Checkbox: View {
let label: String
@Binding var isOn: Bool
var body: some View {
Button {
isOn.toggle()
} label: {
HStack {
Image(systemName: isOn ? "checkmark.square" : "square")
Text(label)
}
.foregroundStyle(.black)
}
}
}
If I click on one checkbox, both of them get toggled. However, if I simply remove the checkboxes from the VStack, then I am able to toggle them both independently. I believe this is a bug with bool Bindings, but if anyone can point out why I am mistaken that would be much appreciated :)