不能指定'() – > Void'types的值来input'(( – ) – > Void)!'
更新到Xcode 8testing版6后,我得到错误
不能指定'() – > Void'types的值来input'(( – ) – > 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 }
任何修复build议?
看来你的问题与此有关: SE-0103
尝试将您的addButton(_:action:)
的方法标题转换为:
public func addButton(_ title:String, action:@escaping ()->Void)->SCLButton {
来自新beta的诊断信息是如此混乱和不足,像往常一样,但使您的财产简单的非可选var action:()->Void = {}
会给你一些更有用的信息。