Not getting value change using UISlider.observer

I am attempting to detect changes of a UISlider value using the observer option but I am not getting any output. Selected parts of code here

class MainViewController: UIViewController {

    @IBOutlet weak var speedSlider: UISlider!

    var speedSliderObserver:  NSKeyValueObservation?

    override func viewDidLoad() {   super.viewDidLoad()         setSettings()     }

    func setSettings() {

        speedSliderObserver = speedSlider.observe(.value, options: [.old, .new]) { object, change in             print("speedSlider from: (change.oldValue!), to: (change.newValue!)")         } }

Am I using observe correctly or is there some other way?

Replies

It all ok now. Did not need to use observer. Just needed to drag the slider button to add an Action and use that for value updates.