title: Swift: Determine whether a type conforms to protocol results an error
body: <p>when I'm trying to determine whether a type conforms to a protocol I get an error:</p>
  <blockquote>
  <p>Protocol can only be used as a generic constraint because it has Self or associated type requirements</p>
  </blockquote>
  <p>Here's a simplified version of my code:</p>
  <pre class="lang-swift prettyprint-override"><code>protocol FooProtocol {
      static func combine(foo: Self, with element: Any) -&gt; Self
  }
  
  func combine&lt;T&gt;(foo: T, with element: Any) -&gt; T? {
      if let F = T.self as? FooProtocol.Type { // Error in here
          return F.combine(foo: foo, with: element)
      } else {
          return nil
      }
  }
  </code></pre>
  <p>I know I can just do this:</p>
  <pre class="lang-swift prettyprint-override"><code>func combine&lt;T: FooProtocol&gt;(foo: T, with element: Any) -&gt; T {
      return T.combine(foo: foo, with: element)
  }
  </code></pre>
  <p>But it's not what I need, what I need is that you can call the <code>combine(foo:with:)</code> function with any type, and if this type does not conform to <code>FooProtocol</code> then <code>nil</code> will get returned.</p>
  <p>Thanks!</p>