<div dir="ltr">As of Swift 2.2, if a variable has a closure type of e.g. () -> Shape, a closure of type () -> Circle would be considered a match. If a class implements 'func make() -> Shape', a subclass implementing 'func make() -> Circle' has to override. However, if a protocol requires a 'func make() -> Shape', a type implementing 'func make() -> Circle' isn't considered to be conforming. That does seem strange.</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 18, 2016 at 12:55 AM, Yogev Sitton via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>In what way?<div><div class="h5"><br><br><br><br><br>
<div class="gmail_quote">On Sun, Apr 17, 2016 at 3:53 PM -0700, "Howard Lovatt" <span dir="ltr"><<a href="mailto:howard.lovatt@gmail.com" target="_blank">howard.lovatt@gmail.com</a>></span> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="3D"ltr"">
I think this should be part of completing generics.<br><br>On Sunday, 17 April 2016, Yogev Sitton via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> 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 have a class that is conforming to a protocol with a method that requires a specific return type.<div>In case I want to return a subclass of the return type I am forced to use an associatedtype that feels like a hack.</div><div><br></div><div>As an example:</div><div><br></div><div><div><i>protocol MyShapeProtocol {</i></div><div><i> func make() -> Shape?</i></div><div><i>}</i></div><div><i><br></i></div><div><i>class Circle : Shape {}</i></div><div><i><br></i></div><div><i>class CircleMaker : MyShapeProtocol{</i></div><div><i> func make() -> Circle? {</i></div><div><i> return Circle()</i></div><div><i> }</i></div><div><i>}</i></div></div><div><br></div><div>This will not work.</div><div>For that to work I’ll need to use toe associatedtype “hack”:</div><div><br></div><div><div><i>protocol MyShapeProtocol {</i></div><div><i> associatedtype ShapeReturnType : Shape</i></div><div><i> func make() -> ShapeReturnType?</i></div><div><i>}</i></div><div><i><br></i></div><div><div><i>class Circle : Shape {}</i></div></div><div><i><br></i></div><div><i>class CircleMaker : MyShapeProtocol{</i></div><div><i> func make() -> Circle? {</i></div><div><i> return Circle()</i></div><div><i> }</i></div><div><i>}</i></div></div><div><br></div><div>Is there a real value in adding the associatedtype line?</div></div></blockquote><br><br>-- <br>-- Howard.<br>
</div>
</blockquote>
</div>
</div></div></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>