<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&nbsp;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:&nbsp;<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 &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; 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&nbsp;ProtocolA {<br class="">&nbsp; &nbsp;&nbsp;associatedtype&nbsp;U<br class="">&nbsp; &nbsp;&nbsp;var&nbsp;someVariable : U {&nbsp;get&nbsp;set&nbsp;}<br class="">&nbsp; &nbsp;&nbsp;func&nbsp;someFunction(_&nbsp;x:U) -&gt; U<br class="">}<br class=""><br class="">class&nbsp;SomeClass&lt;T&gt; {<br class="">&nbsp; &nbsp;&nbsp;var&nbsp;someProperty :&nbsp;ProtocolA&nbsp;where&nbsp;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&lt;U&gt; { ... }</div><div class=""><br class=""></div><div class="">And now I am using it like this:</div><div class="">class SomeClass&lt;T&gt; {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var someProperty: NewClass&lt;T&gt;</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&nbsp;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>