<div id="compose" contenteditable="true" style="padding-left: 20px; padding-right: 20px; padding-bottom: 8px;"><div>'Default' implementation in protocol extension is used as fail safe. You should not consider it like something super class does. If you want it that way, use class inheritance instead.</div><div><br></div><div>Zhaoxin<br><br><div class="acompli_signature">Get <a href="https://aka.ms/o0ukef">Outlook for iOS</a></div><br></div></div>
                <div class="gmail_quote">_____________________________<br>From: Rick Mann via swift-users &lt;<a dir="ltr" href="mailto:swift-users@swift.org" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="0">swift-users@swift.org</a>&gt;<br>Sent: 星期三, 十一月 16, 2016 07:51<br>Subject: Re: [swift-users] Attempting to call default protocol implementation crashes Playground<br>To: Dan Loewenherz &lt;<a dir="ltr" href="mailto:dan@lionheartsw.com" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="1">dan@lionheartsw.com</a>&gt;<br>Cc: swift-users &lt;<a dir="ltr" href="mailto:swift-users@swift.org" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="2">swift-users@swift.org</a>&gt;<br><br><br>Well, this is a standard protocol default implementation. I was experimenting to see if it was possible to call the default implementation after providing a concrete implementation.<br><br>&gt; On Nov 15, 2016, at 14:47 , Dan Loewenherz &lt;<a dir="ltr" href="mailto:dan@lionheartsw.com" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="3">dan@lionheartsw.com</a>&gt; wrote:<br>&gt; <br>&gt; What are you trying to accomplish here, more concretely?<br>&gt; <br>&gt; My first thought is that you shouldn't implement the same function in both a protocol extension and a conforming class. Why not just give them different names and call the function from within the extension instead of from the class? E.g.<br>&gt; <br>&gt; protocol FooPro {<br>&gt;     func _fooFunc()<br>&gt; }<br>&gt; <br>&gt; extension FooPro {<br>&gt;     func fooFunc() {<br>&gt;         print("fooFunc default")<br>&gt;         _fooFunc()<br>&gt;     }<br>&gt; }<br>&gt; <br>&gt; class FooClass: FooPro {<br>&gt;     func _fooFunc() {<br>&gt;         print("fooFunc FooClass")<br>&gt;     }<br>&gt; }<br>&gt; <br>&gt; let fc = FooClass()<br>&gt; fc.fooFunc()<br>&gt; <br>&gt; Dan<br>&gt; <br>&gt; On Tue, Nov 15, 2016 at 4:28 PM, Rick Mann via swift-users &lt;<a dir="ltr" href="mailto:swift-users@swift.org" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="4">swift-users@swift.org</a>&gt; wrote:<br>&gt; The following gives Xcode 8.1 a very hard time. Eventually I get a Bad Access on the last line. I'm guessing it's a recursive call. Is there any way to call the default implementation from a "real" implementation?<br>&gt; <br>&gt; protocol FooPro<br>&gt; {<br>&gt;         func fooFunc()<br>&gt; }<br>&gt; <br>&gt; extension FooPro<br>&gt; {<br>&gt;         func<br>&gt;         fooFunc()<br>&gt;         {<br>&gt;                 print("fooFunc default")<br>&gt;         }<br>&gt; }<br>&gt; <br>&gt; class FooClass : FooPro<br>&gt; {<br>&gt;         func<br>&gt;         fooFunc()<br>&gt;         {<br>&gt;                 (self as FooPro).fooFunc()<br>&gt;                 print("fooFunc FooClass")<br>&gt;         }<br>&gt; }<br>&gt; <br>&gt; let fc: FooPro = FooClass()<br>&gt; fc.fooFunc()<br>&gt; <br>&gt; <br>&gt; Thanks!<br>&gt; <br>&gt; <br>&gt; --<br>&gt; Rick Mann<br>&gt; <a dir="ltr" href="mailto:rmann@latencyzero.com" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="6">rmann@latencyzero.com</a><br>&gt; <br>&gt; <br>&gt; _______________________________________________<br>&gt; swift-users mailing list<br>&gt; <a dir="ltr" href="mailto:swift-users@swift.org" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="7">swift-users@swift.org</a><br>&gt; <a dir="ltr" href="https://lists.swift.org/mailman/listinfo/swift-users" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="8">https://lists.swift.org/mailman/listinfo/swift-users</a><br>&gt; <br><br><br>-- <br>Rick Mann<br><a dir="ltr" href="mailto:rmann@latencyzero.com" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="9">rmann@latencyzero.com</a><br><br><br>_______________________________________________<br>swift-users mailing list<br><a dir="ltr" href="mailto:swift-users@swift.org" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="10">swift-users@swift.org</a><br><a dir="ltr" href="https://lists.swift.org/mailman/listinfo/swift-users" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="11">https://lists.swift.org/mailman/listinfo/swift-users</a><br><br><br></div>