What is the equivalent of `UIViewController<MyProtocol>` of objc in swift?
objective-c, swift
Solution
I don't understand objective-c well but it looks than even in it you use generics to achieve what you are asking for (cant say that for sure because I have no idea about generics syntax in obj-c). In swift using generics your setupViewController function should like this:
func setupController<T:UIViewController where T:MyProtocol>(controller : T){
}
and this in functionality terms is completely equivalent with method from objective-c
Problem
I want to declare a function that accepts an UIViewController that adopts a particular protocol. How can I declare this in swift? ``` protocol MyProtocol { func subtitle() -> String func saveResults() } func setupViewController(controller: UIViewController<MyProtocol> ) { // ERROR here ... } ``` Why I want to do this: Because I have created a container view controller that has several children of different classes. What they have in common is `MyProtocol` and off-course the fact they inherit (directly or indirectly) `UIViewController`. So one of my methods has one of this controllers as a parameter. I want to tell the compiler the most specific information possible: the object is an `UIViewController` and conforms to `MyProtocol`. How Can I declare this?