[swift-evolution] [Idea] How to eliminate 'optional' protocol requirements

Matthew Johnson matthew at anandabits.com
Mon Apr 11 12:30:54 CDT 2016

Sent from my iPad

> On Apr 11, 2016, at 12:15 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>> On Apr 7, 2016, at 5:12 PM, Douglas Gregor via swift-evolution <swift-evolution at swift.org> wrote:
>> One could perhaps work around (a), (b), and (d) by allowing compound (function-like) names like tableView(_:viewFor:row:) for properties, and work around (c) by allowing a method to satisfy the requirement for a read-only property, but at this point you’ve invented more language hacks than the existing @objc-only optional requirements. So, I don’t think there is a solution here.
> To me, compound names for closure properties and satisfying property requirements with methods aren't hacks, they're missing features we ought to support anyway. I strongly prefer implementing those over your proposed solution. It sounds to me like a lot of people using optional protocol requirements *want* the locality of control flow visible in the caller, for optimization or other purposes, and your proposed solution makes this incredibly obscure and magical.

Do you have the same thought for optional closure properties?  If so and heightForRow was an optional closure property it would satisfy all use cases elegantly.  It could have a default implementation that returns nil.  When non-uniform heights are required a normal method implementation can be provided.  Delegates that have uniform row heights some of the time, but not all of the time, would also be supported by implementing the property.

If we decide to favor this approach it would be really nice to be able to import Cocoa delegate protocols this way.  Is that something that might be feasible?

> -Joe
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

More information about the swift-evolution mailing list