I want to declare a variable
var specialVC: UIViewController & MyProtocol.
And I have a function
func doStuff<T: UIViewController & MyProtocol> { ... }
However, when I try to pass in my variable into the doStuff, it says UIViewController doesn't conform to MyProtocol.
class MyClass: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var specialVC: UIViewController & MyProtocol
doStuff(specialVC)
}
func doStuff<T: UIViewController & MyProtocol>(_ vc: T) {}
}
error:
Argument type 'UIViewController' does not conform to expected type 'MyProtocol'
--- Update ---
After looking at Protocol doesn't conform to itself?, I am able to create an extension that specifies a class that conforms to a protocol. However, I won't be able to call doStuff() from this extension.
internal extension MyProtocol where Self: UIViewController {
// call doStuff(self) here somehow?
}