<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="">Hi Trevör,<div class=""><br class=""></div><div class="">What you’re asking for has been discussed extensively and a very thorough proposal was drafted by Austin Zheng: <a href="https://github.com/austinzheng/swift-evolution/blob/az-existentials/proposals/XXXX-enhanced-existentials.md" class="">https://github.com/austinzheng/swift-evolution/blob/az-existentials/proposals/XXXX-enhanced-existentials.md</a></div><div class=""><br class=""></div><div class="">This is not something that is likely to make it into Swift 4 but is a feature with a lot of community demand so it is likely to be added eventually.</div><div class=""><br class=""></div><div class="">Matthew</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 10, 2017, at 10:46 AM, Trevör ANNE DENISE via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello everyone !<div class=""><br class=""></div><div class="">I am currently writing a project where I would like to do something similar to this:</div><div class=""><br class=""></div><div class=""><font color="#606060" class=""><b class="">protocol ProtocolA {<br class=""> associatedtype U<br class=""> var someVariable : U { get set }<br class=""> func someFunction(_ x:U) -> U<br class="">}<br class=""><br class="">class SomeClass<T> {<br class=""> var someProperty : ProtocolA where ProtocolA.U == T<br class="">}</b></font></div><div class=""><br class=""></div><div class="">But this isn't possible so I had to implement it as a generic class:</div><div class="">class NewClass<U> { ... }</div><div class=""><br class=""></div><div class="">And now I am using it like this:</div><div class="">class SomeClass<T> {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var someProperty: NewClass<T></div><div class="">}</div><div class=""><br class=""></div><div class="">The issue here is that protocols aren't used any more with this approach, and in my case there is no "default" implementation of <i class="">myFunction</i>, so protocols where really useful!!</div><div class=""><br class=""></div><div class="">Is there a better way to do that in the current Swift version?</div><div class=""><br class=""></div><div class="">Today, I came across the proposal SE-0142 (Permit where clauses to constrain associated types), but this only seems to apply inside of protocols, what is your opinion about having similar mechanisms in classes and structs ?</div><div class=""><br class=""></div><div class="">Thank you!</div><div class=""><br class=""></div><div class="">Trevör</div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></body></html>