This has been proposed before in the past by several others (myself being one of them).<br><br>The key problem is that it cannot accommodate retroactive modeling. That is, you would not be able to conform existing types, the code for which you do not control, to a protocol of your own design. Retroactive modeling is an essential feature of Swift protocol-oriented programming.<br><div class="gmail_quote"><div dir="ltr">On Mon, Aug 22, 2016 at 4:30 PM David Cordero via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div><b>The problem:</b></div><div>At the moment, looking at the code of a class or a struct implementing a protocol, it is hard to know what methods are actually implementing the protocol and what other methods are just part of the code of the class or struct.<br></div><div><br></div><div>People are trying to fix this problem with pragma marks or moving the code conforming the protocol to a separate extension, but they are just specific good practices or code styles.</div><div><br></div><div><b>Proposal:</b></div><div>Adding a keyword to the methods conforming protocols. As an example please check the following piece of code which uses the keyword `conform` to explicitly indicate that `myMethod` is a method conforming a protocol.</div><div><br></div><div>```</div><div>protocol MyProtocol {</div><div> func myMethod() -> String</div><div>}</div><div><br></div><div>class MyClass: MyProtocol {</div><div><br></div><div> <b>conform</b> func myMethod() -> String {</div><div> return "Yuhuuu,I am conforming \\o//"</div><div> }</div><div><br></div><div> func whatever() {</div><div> print("I am a boring method and I don't conform anything")</div><div> }</div><div>}</div><div>```</div><div><br></div><div>It would be something similar to the current keyword `override` but for protocols. </div><div><br></div><div>Apart from improving code readability, It would allow the detection, in compilation time, of errors due to code evolution. For example redundant methods that no longer conform anything once the requirement is removed from the protocol for whatever reason.</div><div><br></div><div>Looking forward your opinions and comments.</div><div><br></div><div>Kind Regards</div><div><br></div><div><br></div></div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>