Skip to content

Commit f597255

Browse files
committed
Update package
1 parent 6e7dc6f commit f597255

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Sources/Intermodular/Extensions/SwiftUI/Binding++.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,24 @@ extension Binding {
137137
)
138138
}
139139

140-
public static func boolean<T: Equatable>(_ value: Binding<T?>, equals some: T) -> Binding<Bool> where Value == Bool {
140+
/// Creates a `Binding<Bool>` that reports whether `binding.wrappedValue` equals a given value.
141+
///
142+
/// `binding.wrappedValue` will be set to `nil` only if `binding.wrappedValue` is equal to the given value and the `Boolean` value being set is `false.`
143+
public static func boolean<T: Equatable>(
144+
_ binding: Binding<T?>,
145+
equals value: T
146+
) -> Binding<Bool> where Value == Bool {
141147
.init(
142-
get: { value.wrappedValue == some },
148+
get: {
149+
binding.wrappedValue == value
150+
},
143151
set: { newValue in
144152
if newValue {
145-
value.wrappedValue = some
153+
binding.wrappedValue = value
146154
} else {
147-
value.wrappedValue = nil
155+
if binding.wrappedValue == value {
156+
binding.wrappedValue = nil
157+
}
148158
}
149159
}
150160
)

0 commit comments

Comments
 (0)