title: Initialize class type with a protocol initializer
body: <p>This is my code:</p>
  
  <pre><code>import UIKit
  
  public protocol Initializer {
      init(id: String)
  }
  
  public class A: UIView, Initializer {
      public required init(id: String) {
          super.init(frame: CGRect.zero)
      }
  
      public required init?(coder aDecoder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
  }
  
  class C {
      public static func someFunc&lt;T&gt;(myClass: T.Type) -&gt; T where T: Initializer {
          return myClass.init(id: "test")
      }
  }
  
  let myType: UIView.Type = A.self
  let myType2: Initializer.Type = A.self
  
  let myView = C.someFunc(myClass: myType)
  let myView2 = C.someFunc(myClass: myType2)
  
  let myView3 = C.someFunc(myClass: myType as! Initializer.Type)
  let myView4 = C.someFunc(myClass: myType2 as! UIView.Type)
  </code></pre>
  
  <p>I get errors on all my attempts to call <code>C.someFunc</code> function. This is what I want and expect:</p>
  
  <p>I get an array of class types which conforms to the <code>Initializer</code> protocol and are inherted from <code>UIView</code>. I then want to call the <code>someFunc</code> method to call the initializer for me and dynamically choose the class for me, and returns an UIView. Can I say something to the compiler like: 'This is a class which inherts from <code>UIView</code> and conforms to protocol <code>Initializable</code>'?</p>
  
  <p>Edit:</p>
  
  <p>Well some calls to function <code>someFunc</code> works when I cast alot:</p>
  
  <pre><code>class C {
      public static func someFunc&lt;T&gt;(myClass: T.Type) -&gt; T where T: UIView {
          return (myClass as! Initializer.Type).init(id: "test") as! T
      }
  }
  </code></pre>
  
  <p>But isn't there a compile error checker with type constrains available?</p>
  
  <p>Edit 2:</p>
  
  <p>Strangest of all, this is not working:</p>
  
  <pre><code>class C {
      public static func someFunc&lt;T&gt;(myClass: T.Type) -&gt; T where T: Initializer, T: UIView {
          return myClass.init(id: "test") // error
      }
  }
  </code></pre>
  
  <p>error: </p>
  
  <blockquote>
    <p>Argument labels '(id:)' do not match any available overloads</p>
  </blockquote>
  
  <p>Why does this error occured? Type T has to conform to protocol Initializable which means it should have an public initializer with signature id: String. </p>