<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On Nov 2, 2017, at 1:57 PM, Taylor Swift via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Swift architectures use much less inheritance (and class types) in general than equivalent c++ architectures. personally i have never been in a situation where i didn’t need a pure abstract method that was better declared as a protocol requirement.</span></div></blockquote></div><div class=""><br class=""></div><div class="">I think we should beef up protocols a little bit so that they can serve the role of abstract classes. That would make for a nice, clean separation: anything abstract is a protocol, while anything concrete is a class (or struct or enum).</div><div class=""><br class=""></div><div class="">What would protocols need in order to support everything abstract classes can do? First, we'd probably need to extend class constraints to allow a protocol to require you to subclass a given base class:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// Hypothetical replacement for UIControl.</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>protocol UIControl: UIView {</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>func sendAction(_ action: Selector, to target: Any?, for event: UIEvent)</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>extension UIControl {</div><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>func sendAction(_ action: Selector, to target: Any?, for event: UIEvent) {</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">                        </span>UIApplication.shared.sendAction(action, to: target, from: self, for: event)</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>}</div></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><br class=""></div><div class="">Maybe allow them to declare automatically-added storage, perhaps even private to the protocol:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>protocol UIControl: UIView {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>@automatic</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>private var actions: [UIControlEvents: [(target: Any?, action: Selector)]] = [:]</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span></div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>func sendAction(_ action: Selector, to target: Any?, for event: UIEvent)</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>extension UIControl {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>func sendActions(for controlEvents: UIControlEvents) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>for (event, pairs) in actions where event.contains(controlEvents) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                </span>for pair in pairs {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                        </span>sendAction(pair.action, to: pair.target, for: UIApplication.shared.currentEvent)</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                                </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span></div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>func sendAction(_ action: Selector, to target: Any?, for event: UIEvent) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>UIApplication.shared.sendAction(action, to: target, from: self, for: event)</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><br class=""></div><div class="">Probably something like `super` for when you want to override a default implementation but still call it:</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span></div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>class MyButton: UIControl {</div><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>func sendAction(_ action: Selector, to target: Any?, for event: UIEvent) {</div></div><div class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>print("Sending \(action) to \(target)")</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>super(UIControl).sendAction(action, to: target, for: event)</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><br class=""></div><div class="">These are all solid features that would be great additions to protocols, even when they're *not* replacing abstract classes.</div><div class=""><br class=""></div><div class="">
<span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; border-spacing: 0px;"><div class=""><div style="font-size: 12px; " class="">-- </div><div style="font-size: 12px; " class="">Brent Royal-Gordon</div><div style="font-size: 12px; " class="">Architechies</div></div></span>
</div>
<br class=""></body></html>