<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">That’s exactly my point - thank you for the quick summary Ross.<div class="">Protocols behaves differently than closures and classes.<br class=""><div class=""><br class=""><div class=""><div><blockquote type="cite" class=""><div class="">On Apr 18, 2016, at 12:40 PM, Ross O'Brien <<a href="mailto:narrativium+swift@gmail.com" class="">narrativium+swift@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">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 class=""><div class="gmail_quote">On Mon, Apr 18, 2016 at 12:55 AM, Yogev Sitton via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">In what way?<div class=""><div class="h5"><br class=""><br class=""><br class=""><br class=""><br class="">
<div class="gmail_quote">On Sun, Apr 17, 2016 at 3:53 PM -0700, "Howard Lovatt" <span dir="ltr" class=""><<a href="mailto:howard.lovatt@gmail.com" target="_blank" class="">howard.lovatt@gmail.com</a>></span> wrote:<br class="">
<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="3D"ltr"" class="">
I think this should be part of completing generics.<br class=""><br class="">On Sunday, 17 April 2016, Yogev Sitton via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">I have a class that is conforming to a protocol with a method that requires a specific return type.<div class="">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 class=""><br class=""></div><div class="">As an example:</div><div class=""><br class=""></div><div class=""><div class=""><i class="">protocol MyShapeProtocol {</i></div><div class=""><i class=""> func make() -> Shape?</i></div><div class=""><i class="">}</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">class Circle : Shape {}</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">class CircleMaker : MyShapeProtocol{</i></div><div class=""><i class=""> func make() -> Circle? {</i></div><div class=""><i class=""> return Circle()</i></div><div class=""><i class=""> }</i></div><div class=""><i class="">}</i></div></div><div class=""><br class=""></div><div class="">This will not work.</div><div class="">For that to work I’ll need to use toe associatedtype “hack”:</div><div class=""><br class=""></div><div class=""><div class=""><i class="">protocol MyShapeProtocol {</i></div><div class=""><i class=""> associatedtype ShapeReturnType : Shape</i></div><div class=""><i class=""> func make() -> ShapeReturnType?</i></div><div class=""><i class="">}</i></div><div class=""><i class=""><br class=""></i></div><div class=""><div class=""><i class="">class Circle : Shape {}</i></div></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">class CircleMaker : MyShapeProtocol{</i></div><div class=""><i class=""> func make() -> Circle? {</i></div><div class=""><i class=""> return Circle()</i></div><div class=""><i class=""> }</i></div><div class=""><i class="">}</i></div></div><div class=""><br class=""></div><div class="">Is there a real value in adding the associatedtype line?</div></div></blockquote><br class=""><br class="">-- <br class="">-- Howard.<br class="">
</div>
</blockquote>
</div>
</div></div></div><br class="">_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></div></body></html>