不能分配类型'() - >的值Void'键入'(() - > Void)!' [英] Cannot assign value of type '() -> Void' to type '(() -> Void)!'
本文介绍了不能分配类型'() - >的值Void'键入'(() - > Void)!'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在更新到xcode 8 beta 6之后,我收到错误
after updating to xcode 8 beta 6, I'm getting the error
无法分配'() - > '在以下func块中键入'(( - )Void)!'
Cannot assign value of type '() -> Void' to type '(() -> Void)!'
,第三行:
// 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
}
any
推荐答案
似乎您的问题与此有关:
SE-0103
It seems your issue is related to this: SE-0103
尝试将您的 addButton(_:action:)
的方法标题记录到:
Try chaging the method header of your addButton(_:action:)
to:
public func addButton(_ title:String, action:@escaping ()->Void)->SCLButton {
来自新betas的诊断消息像往常一样令人困惑和不足,但使您的属性非可选 var action:() - > Void = {}
会给你一些更有用的信息。
The diagnostic messages from new betas are so confusing and inadequate as usual, but making your property simply non-Optional var action:()->Void = {}
will give you a little more useful info.
这篇关于不能分配类型'() - >的值Void'键入'(() - > Void)!'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文