Convert Binding

2020-11-05 01:34:55 SwiftUI


extension Binding where Value == Int {
    public func float() -> Binding<Float> {
        return Binding<Float>(get:{ Float(self.wrappedValue) },
            set: { self.wrappedValue = Int($0)})
    }
}


...

// self.$data.count is Binding<Int>
Slider(value: self.$data.count.float(), in:1...16) {
                Text("Number")
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Powered By Valine
v1.5.2