“'_'只能出现在模式中或赋值的左侧”-创建闭包时出错

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

我正在创建一个闭包,以便从我正在创建的框架之外的故事板调用。 但是,当尝试通过 SO post 的指导实施上述关闭时,我收到以下错误:

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

这是我的 swift 文件中的当前代码:

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

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

    sliderChangeforward(sender)
    
}

非常感谢任何帮助。

你省略了等号。

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