Swift代理报错Optional can only be ap
2017-06-05 本文已影响91人
否极泰来_L

Swift是不允许设置协议的可选的状态,协议声明的方法都是必须实现的。
****解决方案一****

添加@objc修饰协议。
****解决方案二****
实现所有声明的方法
****我的做法****
在父类中实现声明的方法
class HLBaseViewController: UIViewController, UIViewCollectEventsDelegate
func uiView(ClickRefreshWithParams params: AnyObject?) {
}
func uiView(uiView: UIView?, CollectEventsType type: AnyObject?, withParams params: AnyObject?) {
}
在子类中替换掉要实现的方法
class HomeViewController: HLBaseViewController
override func uiView(uiView: UIView?, CollectEventsType type: AnyObject?, withParams params: AnyObject?) {
NSLog("789")
}