首先,我有一个协议来检查一致性:
protocol NavigationDelegatable{
associatedtype NavigationDelegateConformance
var navigationDelegate: NavigationDelegateConformance? {get set}
}
然后在ViewController中我实现:
class UserDataViewController: UIViewController, NavigationDelegatable {
var navigationDelegate: UserDataNavigationDelegate?
}
UserDataNavigationDelegate是一些其他协议
protocol UserDataNavigationDelegate: class {
func edit(user: NSData)
}
然后在其他扩展名
class func instantiateViewController(fromStoryboardName name: UIStoryboard.Name, withIdentifier identifier: UIStoryboard.Identifier, withNavigationDelegate navigationDelegate: AnyClass) -> UIViewController? {
if let viewController = UIStoryboard(name: "wololo").instantiateViewController(withIdentifier: "bar") as? NavigationDelegatable {
viewController.navigationDelegate = navigationDelegate
}
return viewController
}
我没有将要实例化的类,我只需要检查它是否符合NavigationDelegatable来设置属性,然后我就得到了错误:
协议'NavigationDelegatable'只能用作通用约束,因为 它有自我或相关的类型要求
有办法吗?