Mik*_*ong 3 error-handling xcode ios swift
更新到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
}
Run Code Online (Sandbox Code Playgroud)
关于修复的任何建议?
看来你的问题与此有关: SE-0103
尝试查找你的方法标题addButton(_:action:):
public func addButton(_ title:String, action:@escaping ()->Void)->SCLButton {
Run Code Online (Sandbox Code Playgroud)
来自新beta的诊断消息是如此令人困惑和不适当,但让你的属性只是非可选var action:()->Void = {}将给你一些更有用的信息.
| 归档时间: |
|
| 查看次数: |
2632 次 |
| 最近记录: |