Swift 4: Cannot assign value of type '(_) -> Void' to type '(() -> ())?'

Viewed 9248

XCode 9, Beta 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)
    }

Getting the error: Cannot assign value of type '(_) -> Void' to type '(() -> ())?'

4 Answers

I had a similar problem, I resolved this way:

button.clickAction = { _ in
        action()
        Sound.playSound(Sounds.Button)
    }

Hope it helps you.

Related