我希望将这个函数定义在协议里:
func slideToRight(currentViewController viewController: UIViewController, completion: ((Bool)->())? = nil) {
// do some stuff
}
但是当我编写这样的协议时:
protocol SomeDelegate {
func slideToRight(currentViewController viewController: UIViewController, completion: ((Bool)->())? = nil)
}
我遇到了一个错误:
协议方法中不允许默认参数
我知道,我可以这样定义签名:
protocol SomeDelegate {
func slideToRight(currentViewController viewController: UIViewController, completion: ((Bool)->())?)
}
但是,如果我不使用"completion"单词来调用缺失函数:
slideToRight(currentViewController viewController: vc)
extension SomeDelegate where Self: UIViewController { func slideToRight(completion: ((Bool)->())? = nil) { } }
- Leo Dabus