<div dir="ltr">Swift 3.0 will bring many changes to protocols. I expect these issues will be discussed a lot more once 2.2 is shipped.<div><br></div><div>-david</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 16, 2016 at 11:54 AM, David Sweeris via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">I think it’s something to do with subclasses overriding the method and potentially returning a type that’s different that what the compiler is expecting. Or something like that. <div><br></div><div>I hope it gets addressed at some point, though, because it drives me nuts, too.<div><br><div><div><div><blockquote type="cite"><div><div class="h5"><div>On Feb 16, 2016, at 1:47 PM, Diego Sánchez via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br></div></div><div><div><div class="h5"><div dir="ltr">Hi all,<div><br></div><div>Covariance works properly with classes:</div><div><p><span>class</span><span> M</span>yType {}<br>class MySubtype: MyType {}<br></p><div>class MyClass {</div><div>    func createMyType() -&gt; MyType {</div><div>        return MyType()</div><div>    }</div><div>}</div><div><br></div><div>class MySubClass: MyClass {</div><div>    override func createMyType() -&gt; MySubtype {</div><div>        return MySubtype()</div><div>    }</div><div>}</div><div><br></div><div>However it doesn&#39;t work for protocol conformance:</div><div><br></div><div><div>protocol MyProtocol {</div><div>    func createMyType() -&gt; MyType</div><div>}</div><div><br></div><div>class MyConformingClass: MyProtocol {</div><div>    func createMyType() -&gt; MySubtype {</div><div>        return MySubtype()</div><div>    }</div><div>}</div></div><div><br></div><div>Compiler error for this case:</div><div><div>error: type &#39;MyConformingClass&#39; does not conform to protocol &#39;MyProtocol&#39;</div><div>note: protocol requires function &#39;createMyType()&#39; with type &#39;() -&gt; MyType&#39;</div><div>note: candidate has non-matching type &#39;() -&gt; MySubtype&#39;</div></div><div><br></div><div>I know I can fix it by using associated objects in MyProtocol definition, but then if I want to declare a property of type MyProtocol I have to go dancing with generics everywhere.</div><div><br></div><div>Is this a known limitation/bug? Any plans to improve this?</div><div><br></div><div>Cheers,</div><div>Diego</div><div><span></span><br></div></div></div></div></div>
_______________________________________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div></div></div></div><br>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>