diff options
Diffstat (limited to 'Hotline/Utility')
| -rw-r--r-- | Hotline/Utility/FoundationExtensions.swift | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Hotline/Utility/FoundationExtensions.swift b/Hotline/Utility/FoundationExtensions.swift index 9cf2992..b5a2c34 100644 --- a/Hotline/Utility/FoundationExtensions.swift +++ b/Hotline/Utility/FoundationExtensions.swift @@ -594,3 +594,21 @@ extension FourCharCode { return String(bytes: bytes, encoding: .ascii) ?? "" } } + +extension Binding where Value: OptionSet, Value == Value.Element { + func bindedValue(_ options: Value) -> Bool { + return wrappedValue.contains(options) + } + + func bind(_ options: Value) -> Binding<Bool> { + return .init { () -> Bool in + self.wrappedValue.contains(options) + } set: { newValue in + if newValue { + self.wrappedValue.insert(options) + } else { + self.wrappedValue.remove(options) + } + } + } +} |