iosswiftuiviewclosuresibaction

"'_' can only appear in a pattern or on the left side of an assignment"-Error when creating closure


I'm creating a closure to call from a storyboard outside the framework I'm creating. However, when trying to implement said closure through the guidance of this SO post, I'm getting the following errors:

1. '_' can only appear in a pattern or on the left side of an assignment
2. Consecutive statements on a line must be separated by ';'
3. Expected expression

Here is the current code inside my swift file:

//Here is where I'm getting the mentioned 3 errors
var sliderChangeforward: (UISlider) -> Void { _ in }

@IBAction func sliderDidChange(_ sender: UISlider){
    
    ...

    sliderChangeforward(sender)
    
}

Any help is greatly appreciated.


Solution

  • You omitted the equals sign.

    var sliderChangeforward: (UISlider) -> Void = { _ in }