For a while I've thought it would be useful to have a way to refer to the protocol's default implementation, even when you provide your own. We could possibly do away with most people's concerns and optional methods if we could do something like this:<div><br></div><div>if MyProtocol.someMethod === Self.someMethod {</div><div>}<span></span></div><div><br>On Sunday, 10 April 2016, Антон Жилин <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Here is how I would like this to be implemented.<br></div><div><br></div><div>1. Optional method requirements will be represented in Swift as methods having import-only attribute @optional and defaulted to be fatalError()</div><div><br></div><div>2. On the inside, this default implementation will not define a method. These objects will not respond to corresponding selector unless the default implementation is overridden.</div><div><br></div><div>3. Calls from Swift side will turn into checks with fatalError()</div><div><br></div><div>4. The only way to check existence of such method from Swift will be `responds(to: Selector)`</div><div><br></div><div>Example:</div><div><br></div><div>// Objective-C protocol is imported as:</div><div>protocol <span style="color:rgb(0,0,0);white-space:pre-wrap">NSTableViewDelegate {</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"> @optional </span><span style="color:rgb(0,0,0);white-space:pre-wrap">func tableView(_: NSTableView, viewFor: NSTableColumn, row: Int) -> NSView?</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"> @optional </span><font color="#000000"><span style="white-space:pre-wrap">func tableView(_: NSTableView, heightOfRow: Int) -> CGFloat</span></font></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap">}</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap">extension NSTableViewDelegate {</span></div><span style="color:rgb(0,0,0);white-space:pre-wrap"> @optional </span><span style="color:rgb(0,0,0);white-space:pre-wrap">func tableView(_: NSTableView, viewFor: NSTableColumn, row: Int) -> NSView? {</span><div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"> fatalError("Unimplemented")</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"> }</span></div><span style="color:rgb(0,0,0);white-space:pre-wrap"> @optional </span><font color="#000000"><span style="white-space:pre-wrap">func tableView(_: NSTableView, heightOfRow: Int) -> CGFloat {</span></font></div><div><font color="#000000"><span style="white-space:pre-wrap"> </span></font><span style="color:rgb(0,0,0);white-space:pre-wrap">fatalError("Unimplemented")</span><div><span style="color:rgb(0,0,0);white-space:pre-wrap"> }</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap">}</span></div><div><br></div><div>class MyDelegate : <span style="color:rgb(0,0,0);white-space:pre-wrap">NSTableViewDelegate {</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"> </span><span style="color:rgb(0,0,0);white-space:pre-wrap">@optional </span><span style="color:rgb(0,0,0);white-space:pre-wrap">func tableView(_: NSTableView, viewFor: NSTableColumn, row: Int) -> NSView? {</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"> //...</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"> }</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap">}</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"><br></span></div><div><font color="#000000"><span style="white-space:pre-wrap">getTableViewDelegate().tableView(x, heightOfRow: y) // will fatalError() if not responds to selector</span></font></div><div><font color="#000000"><span style="white-space:pre-wrap">if </span></font><span style="color:rgb(0,0,0);white-space:pre-wrap">getTableViewDelegate().responds(to: #selector(...)) { ... }</span></div><div><br></div>- Anton</div></div>
</blockquote></div>