2

Is it possible, in any version of Swift, to extend a protocol with mixed class/protocol type constraints? For example, I would like to extend Protocol2 only when Self is a subclass of UIViewController and conforms to Protocol1.

protocol Protocol1 {}
protocol Protocol2 {}

//What I imagine I could do, but it does not compile
extension Protocol2 where Self: UIViewController, Protocol2 {}
Andrew Johnson
  • 579
  • 4
  • 23

1 Answers1

4

Try:

extension Protocol2 where Self: UIViewController, Self: Protocol2 {}