目录
目录README.md

BindBackstop Build

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)
    }
}

License

BindBackstop is available under the MIT license.

关于
33.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号