<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 28, 2016 at 12:25 PM, Erica Sadun <span dir="ltr"><<a href="mailto:erica@ericasadun.com" target="_blank">erica@ericasadun.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span class="">><br>
> On Apr 28, 2016, at 11:05 AM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com">xiaodi.wu@gmail.com</a>> wrote:<br>
><br>
> How is retroactive modeling accommodated in this scheme? Say I want to conform three types I don't own to a protocol of my design and supply a default implementation for a protocol requirement. How would I go about it?<br>
<br>
</span>extension NotMyType: ProtocolIdesigned {...}<br>
<br>
extension NotMyProtocol {<br>
required func method1() {...}<br>
override required func method2() {...} // assumes NMP has already provided default<br>
func newThing() {...}<br>
}<br>
<br>
The only tricky bit is when NotMyProtocol already has a default required func implementation and an override required func implementation (although that should be rare). In such case, you probably have to create a new protocol DerivedProtocol: NotMyProtocol and work from there. The override in the DerivedProtocol will then take priority over the override in NotMyProtocol.<br></blockquote><div><br></div><div>Sorry, that's not my question, which doesn't involve protocols I don't own. Let me restate. Given three types I don't own as follows:<br></div><div><br></div><div>```</div><div><div>struct A {</div><div> func frobnicate() { print("A") }</div><div>}</div><div>struct B {</div><div> func frobnicate() { print("B") }</div><div>}</div><div>struct C { }</div></div><div>```</div><div><br></div><div>I want to conform them to a protocol of my own design, Frobnicatable, and supply a default `frobnicate()`:</div><div><br></div><div>```</div><div><div>protocol Frobnicatable {</div><div> func frobnicate()</div><div>}</div><div>extension Frobnicatable {</div><div> func frobnicate() { print("Default") }</div><div>}</div><div>extension A: Frobnicatable { }</div><div>extension B: Frobnicatable { }</div><div>extension C: Frobnicatable { }</div></div><div><br></div><div>let c = C()</div><div>c.frobnicate() // "Default"</div><div>```</div><div><br></div><div><div>(Yes, I realize there are issues regarding static and dynamic dispatch that limit the utility of this particular example--let's leave those aside for now.)</div><div>Where would I affix keywords such as `required` and `override` to make this work after implementation of your proposal?</div></div><div><br></div></div></div></div>