<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 <<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>><br>Sent: 星期三, 十一月 16, 2016 07:51<br>Subject: Re: [swift-users] Attempting to call default protocol implementation crashes Playground<br>To: Dan Loewenherz <<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>><br>Cc: swift-users <<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>><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>> On Nov 15, 2016, at 14:47 , Dan Loewenherz <<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>> wrote:<br>> <br>> What are you trying to accomplish here, more concretely?<br>> <br>> 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>> <br>> protocol FooPro {<br>> func _fooFunc()<br>> }<br>> <br>> extension FooPro {<br>> func fooFunc() {<br>> print("fooFunc default")<br>> _fooFunc()<br>> }<br>> }<br>> <br>> class FooClass: FooPro {<br>> func _fooFunc() {<br>> print("fooFunc FooClass")<br>> }<br>> }<br>> <br>> let fc = FooClass()<br>> fc.fooFunc()<br>> <br>> Dan<br>> <br>> On Tue, Nov 15, 2016 at 4:28 PM, Rick Mann via swift-users <<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>> wrote:<br>> 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>> <br>> protocol FooPro<br>> {<br>> func fooFunc()<br>> }<br>> <br>> extension FooPro<br>> {<br>> func<br>> fooFunc()<br>> {<br>> print("fooFunc default")<br>> }<br>> }<br>> <br>> class FooClass : FooPro<br>> {<br>> func<br>> fooFunc()<br>> {<br>> (self as FooPro).fooFunc()<br>> print("fooFunc FooClass")<br>> }<br>> }<br>> <br>> let fc: FooPro = FooClass()<br>> fc.fooFunc()<br>> <br>> <br>> Thanks!<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="6">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="7">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="8">https://lists.swift.org/mailman/listinfo/swift-users</a><br>> <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>