无法指定类型'() - >的值Void'输入'(() - > Void)!'

时间:2016-08-17 16:44:19

标签: ios swift xcode error-handling

更新到xcode 8 beta 6后,我收到了错误

  

无法指定类型'() - >的值Void'输入'(() - > Void)!'

在以下func块上,第三行:

    // Button sub-class
public class SCLButton: UIButton {
    var actionType = SCLActionType.none
    var target:AnyObject!
    var selector:Selector!
    var action:(()->Void)!

    public init() {
        super.init(frame: CGRect.zero)
    }

    required public init?(coder aDecoder: NSCoder) {
        super.init(coder:aDecoder)
    }

    override public init(frame:CGRect) {
        super.init(frame:frame)
    }

//    required public init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
//    }
}
public func addButton(_ title:String, action:()->Void)->SCLButton {
    let btn = addButton(title)
    btn.actionType = SCLActionType.closure
    btn.action = action // here is where the error occurs
    btn.addTarget(self, action:#selector(SCLAlertView.buttonTapped(_:)), for:.touchUpInside)
    btn.addTarget(self, action:#selector(SCLAlertView.buttonTapDown(_:)), for:[.touchDown, .touchDragEnter])
    btn.addTarget(self, action:#selector(SCLAlertView.buttonRelease(_:)), for:[.touchUpInside, .touchUpOutside, .touchCancel, .touchDragOutside] )
    return btn
}

有关修复的任何建议吗?

1 个答案:

答案 0 :(得分:5)

看来你的问题与此有关: SE-0103

尝试将addButton(_:action:)的方法标题追溯到:

public func addButton(_ title:String, action:@escaping ()->Void)->SCLButton {

来自新测试版的诊断消息如此混乱且不充分,但使您的属性完全不可选var action:()->Void = {}将为您提供更多有用的信息。