title: Declare variable of type UIView conforming to a protocol in Swift 2
body: <p>I need to declare a variable of type <code>UIView</code> which also conforms to <code>MyProtocol</code>:</p>
  
  <pre><code>protocol MyProtocol: class {
      func foobar()
  }
  
  class MyClass {
      var myView: UIView&lt;MyProtocol&gt;! // Error: Cannot specialize non-generic type 'UIView'
  }
  </code></pre>
  
  <p>However I get the compiler error: Cannot specialize non-generic type 'UIView'.</p>
  
  <p>I need to access methods on the variable from <code>UIView</code> and <code>MyProtocol</code>.</p>
  
  <p>What is the correct variable declaration to support these requirements?</p>
  
  <p>If it makes any difference, only <code>UIView</code> subclasses will implement the protocol. Currently I add protocol conformance via extensions.</p>
  
  <p>I found this answer: <a href="https://stackoverflow.com/a/25771265/233602">https://stackoverflow.com/a/25771265/233602</a> but it's not clear if that answer is still the best option going in when writing in Swift 2.</p>