Aben's Blog

vuePress-theme-reco Aben    2020 - 2025
Aben's Blog Aben's Blog

Choose mode

  • dark
  • auto
  • light
Home
Category
  • Docker
  • Node.js
  • golang
  • iOS
  • macOS
Tag
TimeLine
More
  • GitHub
  • Backend
author-avatar

Aben

21

Article

24

Tag

Home
Category
  • Docker
  • Node.js
  • golang
  • iOS
  • macOS
Tag
TimeLine
More
  • GitHub
  • Backend

Convert Binding<Int> to Binding<Float>

vuePress-theme-reco Aben    2020 - 2025

Convert Binding

Aben 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