Created
October 13, 2020 21:01
-
-
Save dfrobison/c0fd76a6e47cef87787b45fab28cf4ef to your computer and use it in GitHub Desktop.
Revisions
-
dfrobison created this gist
Oct 13, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ import SwiftUI struct ContentView: View { @State private var rating = 0.0 var body: some View { Slider(value: $rating.onChange(sliderChanged)) } func sliderChanged(_ value: Double) { print("Rating changed to \(value)") } } extension Binding { func onChange(_ handler: @escaping (Value) -> Void) -> Binding<Value> { Binding( get: { self.wrappedValue }, set: { newValue in self.wrappedValue = newValue handler(newValue) } ) } }