3

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.

RodolfoAntonici
  • 1,555
  • 21
  • 34
  • Hello Leo, it doesn't work, the error message says about using Self will cause the same problem. By the way, could you please remove the duplicated mark? Because it's not duplicated. – RodolfoAntonici Oct 05 '17 at 13:00
  • possible duplicate of https://stackoverflow.com/questions/39338692/why-do-i-get-the-error-protocol-can-only-be-used-as-a-generic-constraint-beca – Leo Dabus Oct 05 '17 at 13:03
  • It's not the same, there he didn't tried to cast it to access the property and assign a value to it... – RodolfoAntonici Oct 05 '17 at 13:03

0 Answers0