DEV Community

Cover image for How to call a function when a slider changes in SwiftUI

How to call a function when a slider changes in SwiftUI

Maegan Wilson on January 18, 2020

There are times you might want to call a function when a slider changes in SwiftUI. I did this recently to send out the slider's value to another d...
Collapse
 
lucianoschillagi profile image
Luko • Edited

Hello, I have a question:

How can I detect, when the user moves the slider if the value is incrementing or decrementing?

If the user moves up the slider I need to call a method (for instance: volume up)

If the user moves down the slider I need to call a method (for instance: volume down)

thanks!

Collapse
 
lucianoschillagi profile image
Luko
Collapse
 
retch profile image
Retch • Edited

Helped me a lot, but in "set:" it should be called either newVal or newValue.

Collapse
 
maeganwilson_ profile image
Maegan Wilson

Thanks for catching that! I'll update the post :)