<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="">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></body></html>