title: UIViewController implementing protocol as parameter or return type
body: <p>I have a pattern where I create UIViewControllers that implement a certain protocol. Because I need them to be real UIViewControllers to be able to push them on the stack they always need to be UIViewControllers not some random class implementing the protocol.</p>
  
  <p>At first I thought I could limit the protocol, but I couldn't figure that out. If you have any idea how to solve it at the source, that would even be better. However as a return type it seemed I was more lucky:</p>
  
  <p><a href="https://briancoyner.github.io/2015/11/14/swift-protocol-that-returns-protocol.html" rel="nofollow noreferrer">https://briancoyner.github.io/2015/11/14/swift-protocol-that-returns-protocol.html</a></p>
  
  <pre><code>protocol ModalViewControllerProvider {
  
      typealias V: UIViewController, ModalPresentationCompletion
  
      func viewControllerWithObject(object: AnyObject) -&gt; V
  }
  </code></pre>
  
  <p>This example doesn't work in Swift 3 however, and I couldn't get it to work except with protocol composition, which doesn't work for UIViewController.</p>
  
  <p>I can work around it by return a UIViewController then casting to ModalPresentationCompletion but that's a bit weird for other programmers to recognize.</p>
  
  <p>Can I assure either in the declaration of the protocol itself, or by creating something like a typealias like above a way to ensure that it's both a UIViewController and a certain protocol is always implemented?</p>