协议'someProtocol'只能用作通用约束,因为它具有Self或相关类型要求

时间:2017-10-04 22:11:22

标签: ios swift generics swift-protocols

首先,我有一个协议来检查一致性:

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'只能用作通用约束,因为   它有自我或相关的类型要求

有办法吗?

顺便说一句,它与thisthisthis的问题不同,因为没有人想为通用属性分配值。

0 个答案:

没有答案