Swift generic type conforming to two protocols

Things have been changed in Swift 4: func foo<T: UIViewController> (viewController: T) where T:UIPickerViewDelegate {}


Your code:

func foo<T: UIViewController, UIPickerViewDelegate> (#viewController: T) {}

declares 2 generics parameters:

  • T which is UIViewController. And it's used as viewController parameter type.
  • UIPickerViewDelegate which is Any. And it's not used.

Instead, you should use "Where Clause", like:

func foo<T: UIViewController where T:UIPickerViewDelegate> (#viewController: T) {}