Protocol 'someProtocol' can only be used as generic constraint because it has Self or associated type requirements

Viewed 653

First I have this a protocol to check the conformance:

protocol NavigationDelegatable{
    associatedtype NavigationDelegateConformance
    var navigationDelegate: NavigationDelegateConformance? {get set}
}

Then in ViewController I implement:

class UserDataViewController: UIViewController, NavigationDelegatable {
    var navigationDelegate: UserDataNavigationDelegate?
}

The UserDataNavigationDelegate is some other protocol

protocol UserDataNavigationDelegate: class {
    func edit(user: NSData)
}

Then in other extension

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
}

I don't have the class that will be instantiated, I only need to check if it conforms with NavigationDelegatable to set the property, then I've got the error:

Protocol 'NavigationDelegatable' can only be used as generic constraint because it has Self or associated type requirements

There's a way to do it?

By the way, it's NOT the same question of this, this and this because no one wants to assign a value for the generic property.

0 Answers
Related