【发布时间】:2016-12-24 10:27:30
【问题描述】:
更新到 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
}
对修复有什么建议吗?
【问题讨论】:
-
错误消息只是说预期的类型是
(() -> Void)!(隐式展开可选),但() -> Void(非可选)类型是在action参数中传递的。类型不匹配。 -
检查更新的问题@ozgur
-
那我应该调整什么? @vadian
-
我想
addButton的action参数的签名(属性action不受影响)。 -
检查更新的问题以获取更多详细信息@vadian
标签: ios swift xcode error-handling