<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>+1</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">I'd love to see this in the language. </div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">Hope somebody from the core team will comment on why this is not allowed.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">R+<br><br>Sent from my iPhone</div><div><br>On 27 Feb 2016, at 11:31, Rasmus Kjeldsen via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><div class=""><br class=""></div><div class="">I propose to allow static protocol extension methods to be used directly on the protocol.</div><div class="">This would enable the Factory-pattern to be elegantly implemented as in the example below:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><div style="margin: 0px; line-height: normal;" class="">protocol<span style="font-size: 13px; line-height: normal; color: rgb(0, 0, 0);" class=""> P {}</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal;" class=""><span style="font-size: 12px; line-height: normal;" class="">class</span> A : <span style="font-size: 12px; line-height: normal; color: rgb(79, 129, 135);" class="">P</span> {}</div><div style="margin: 0px; font-size: 13px; line-height: normal;" class=""><span style="font-size: 12px; line-height: normal;" class="">class</span> B : <span style="font-size: 12px; line-height: normal; color: rgb(79, 129, 135);" class="">P</span> {}</div><div style="margin: 0px; font-size: 13px; line-height: normal; min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">extension<span style="font-size: 13px; line-height: normal; color: rgb(0, 0, 0);" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">P</span><span style="font-size: 13px; line-height: normal; color: rgb(0, 0, 0);" class=""> {</span></div><div style="margin: 0px; font-size: 13px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="font-size: 12px; line-height: normal;" class="">static</span> <span style="font-size: 12px; line-height: normal;" class="">func</span> factory(type: <span style="font-size: 12px; line-height: normal; color: rgb(112, 61, 170);" class="">Bool</span>) -> <span style="font-size: 12px; line-height: normal; color: rgb(79, 129, 135);" class="">P</span> { <span style="font-size: 12px; line-height: normal;" class="">return</span> type ? <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">A</span>() : <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">B</span>()}</div><div style="margin: 0px; font-size: 13px; line-height: normal;" class="">}</div><div style="margin: 0px; font-size: 13px; line-height: normal; min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-size: 13px; line-height: normal; color: rgb(0, 0, 0);" class=""> a = </span><span style="font-size: 13px; line-height: normal; color: rgb(79, 129, 135);" class="">P</span><span style="font-size: 13px; line-height: normal; color: rgb(0, 0, 0);" class="">.factory(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">false</span><span style="font-size: 13px; line-height: normal; color: rgb(0, 0, 0);" class="">) </span>// <- Not possible in Swift 2, factory() can only be used on either A or B</div><div class=""><br class=""></div></div></div><div class="">Regards</div><div class=""><br class=""></div>Rasmus Friis Kjeldsen<div class=""><br class=""></div><div class=""><br class=""></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>