【发布时间】:2017-07-17 18:10:11
【问题描述】:
XCode 9,测试版 3。Swift 4。
let button = JumpingButton(x: 0, y: 50, w: 150, h: 300) // JumpingButton: UIButton
//Inside JumpingButton: // var clickAction: (() -> ())?
button.clickAction = { (sender) -> Void in //Error line
action()
Sound.playSound(Sounds.Button)
}
出现错误:无法将类型“(_) -> Void”的值分配给类型“(() -> ())?”
【问题讨论】:
-
button是什么类型?看起来该属性需要一个无参数的闭包。你可以试试button.clickAction = { action(); ... }吗? -
已编辑。有效,想提供答案吗?
-
我添加了答案