title: In swift, how do I return an object of the same type that conforms to a protocol
body: <p>I have the following protocol</p>
  
  <pre><code>protocol JSONInitializable {
      static func initialize(fromJSON: NSDictionary) throws -&gt; Self?
  }
  </code></pre>
  
  <p>Now I'm trying to make that function return whatever class has conformed to the protocol. I.e. if I have class <code>Foo</code> conforming to the protocol, I want to return a <code>Foo</code> object from the method. How can I do this?</p>
  
  <pre><code>extension Foo: JSONInitializable {
      static func initialize(fromJSON: NSDictionary) throws -&gt; Foo? {
      }
  }
  </code></pre>
  
  <p>I get the error:</p>
  
  <blockquote>
    <p>Method 'initialize' in non-final class 'Foo' must return 'Self' to conform to protocol 'JSONInitializable'</p>
  </blockquote>