Skip to content

Write the inverted value through a negated Bool binding - #9

Merged
Jeehut merged 1 commit into
mainfrom
wip/negated-bool-binding
Oct 15, 2026
Merged

Jeehut merged 1 commit into
mainfrom
wip/negated-bool-binding

Conversation

@Jeehut

@Jeehut Jeehut commented Oct 14, 2026

Copy link
Copy Markdown
Member

Overview

prefix func ! on Binding<Bool> wrote the incoming value unchanged instead of inverting it. Toggle(isOn: !$isOff) therefore stored the opposite of what the user chose, and the toggle jumped back. The setter now writes !$0.

Split out of #7.

How this was verified

BindingExtTests.negatedBindingWritesTheInvertedValue sets the negated binding to false and true and checks the stored value.

Red, with main's BindingExt.swift:

✘ Expectation failed: stored == true   (BindingExtTests.swift:17)
✘ Expectation failed: stored == false  (BindingExtTests.swift:20)
✘ Test run with 1 test in 1 suite failed with 2 issues.

Green, this branch:

✔ Test run with 1 test in 1 suite passed.

The setter of `!binding` wrote the new value unchanged into the
original binding, so toggling a control bound to `!$isOff` stored the
opposite of what the user chose.
@Jeehut
Jeehut merged commit 3e3d1ef into main Oct 15, 2026
5 checks passed
@Jeehut
Jeehut deleted the wip/negated-bool-binding branch October 15, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant