Update README.md
For SwiftUI’s Bindings, make a non-optional Binding from an optional one, given a default value.
This is all the code. It’s only published here because I’ve reinvented this too many times.
extension Binding { init(_ source: Binding<Value?>, _ defaultValue: Value) { self.init(get: { () -> Value in return source.wrappedValue ?? defaultValue }) { (value) in source.wrappedValue = value } } } extension Binding { func with<T>(default v: T) -> Binding<T> where Value == T? { return Binding<T>(self, v) } }
BindBackstop is available under the MIT license.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
BindBackstop
For SwiftUI’s Bindings, make a non-optional Binding from an optional one, given a default value.
This is all the code. It’s only published here because I’ve reinvented this too many times.
License
BindBackstop is available under the MIT license.