<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I do think this would indeed be a feature worth having, but it would need design. There's also a simple workaround for now: put the default implementation in another method or a free function.</div><div class=""><br class=""></div><div class="">Jordan</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 8, 2015, at 9:43, Mateusz Zajac via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="margin: 0px; padding: 0px; color: rgb(51, 51, 51); font-family: Arial, sans-serif; font-size: 14px;" class="">If you define a simple protocol like:</div><div class="panel code" style="margin: 9px 0px; padding: 0px; border: 1px solid rgb(204, 204, 204); background-color: rgb(245, 245, 245); line-height: 1.33333333333333; font-family: monospace; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; color: rgb(51, 51, 51);"><div class="codeContent panelContent" style="margin: 0px; padding: 9px 12px;"><pre class="code-java" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal;">protocol Foo {
    func testPrint()
}
</pre></div></div><p style="margin: 10px 0px 0px; padding: 0px; color: rgb(51, 51, 51); font-family: Arial, sans-serif; font-size: 14px;" class="">And than you provide a default implementation for testPrint() method in protocol extensions like:</p><div class="panel code" style="margin: 9px 0px; padding: 0px; border: 1px solid rgb(204, 204, 204); background-color: rgb(245, 245, 245); line-height: 1.33333333333333; font-family: monospace; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; color: rgb(51, 51, 51);"><div class="codeContent panelContent" style="margin: 0px; padding: 9px 12px;"><pre class="code-java" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal;">extension Foo {
    func testPrint() {
        print(<span class="code-quote" style="color: rgb(0, 145, 0);">"Protocol extension call"</span>)
    }
}
</pre></div></div><p style="margin: 10px 0px 0px; padding: 0px; color: rgb(51, 51, 51); font-family: Arial, sans-serif; font-size: 14px;" class="">You aren't allowed to call the fault implementation from the structure eg.</p><div class="panel code" style="margin: 9px 0px; padding: 0px; border: 1px solid rgb(204, 204, 204); background-color: rgb(245, 245, 245); line-height: 1.33333333333333; font-family: monospace; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; color: rgb(51, 51, 51);"><div class="codeContent panelContent" style="margin: 0px; padding: 9px 12px;"><pre class="code-java" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal;">struct Bar: Foo {
    func testPrint() {
        self.testPrint()
        print(<span class="code-quote" style="color: rgb(0, 145, 0);">"Call from struct"</span>)
    }
}
</pre></div></div><p style="margin: 10px 0px 0px; padding: 0px; color: rgb(51, 51, 51); font-family: Arial, sans-serif; font-size: 14px;" class="">This is some sort of limitation as often happens that a default implementation is providing a major part of implementation and only one, simple line is changed in actual struct implementation. If you're using classes you can achieve this by creating a base class and calling a method on super. If you consider structs, there's no such possibility and you always have to write a whole implementation from scratch in each structure which conforms to the protocol.</p><hr style="color: rgb(51, 51, 51); font-family: Arial, sans-serif; font-size: 14px;" class=""><p style="margin: 10px 0px 0px; padding: 0px; color: rgb(51, 51, 51); font-family: Arial, sans-serif; font-size: 14px;" class="">You can use composition by creating nested structure, but it's neither logical nor clean... It's rather a hack...</p><div class="panel code" style="margin: 9px 0px; padding: 0px; border: 1px solid rgb(204, 204, 204); background-color: rgb(245, 245, 245); line-height: 1.33333333333333; font-family: monospace; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; color: rgb(51, 51, 51);"><div class="codeContent panelContent" style="margin: 0px; padding: 9px 12px;"><pre class="code-java" style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-height: 30em; overflow: auto; white-space: pre-wrap; word-wrap: normal;">struct Bar: Foo {
    func testPrint() {
        <span class="code-comment" style="color: rgb(128, 128, 128);">// Calling <span class="code-keyword">default</span> implementation
</span>        struct Dummy : Foo {}
        let dummy = Dummy()
        dummy.testPrint()
        print(<span class="code-quote" style="color: rgb(0, 145, 0);">"Call from struct"</span>)
    }
}</pre></div></div><div class=""><br class=""></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=f6VunEbxOyO0-2FacKqVTeu6pGEEellWH1YmuP-2Bt5lLhPBy1jDFbC6KFLFvn95sS96Jlkc3RnlL7-2BX-2Fzq44NkUXc99npm7sMQuit0t7Wy-2BenB4JDMmqcNFS81Xtgbs8j-2FgMFkZMAozC-2FRso7ZqKJgsDdPsaP4rf8czuhPVkvq8P8LZR3WxNycBtm7-2BBdj57xspqbNpfEg87hqG0iyFqwH2Y8ymwpJTQNkefpHbKbV71VU-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>