ChWebsiteApp/CHDataManagement/Extensions/Binding+Extension.swift
Christoph Hagen 0989f06d87 First version
2024-10-14 19:22:32 +02:00

15 lines
418 B
Swift

import SwiftUI
public extension Binding where Value: Equatable, Value: Sendable {
init(_ source: Binding<Value?>, replacingNilWith nilProxy: Value) {
self.init(
get: { source.wrappedValue ?? nilProxy },
set: { newValue in
if newValue == nilProxy { source.wrappedValue = nil }
else { source.wrappedValue = newValue }
}
)
}
}