[swift-evolution] [Pitch] Requiring proactive overrides for default protocol implementations.

Erica Sadun erica at ericasadun.com
Thu Apr 28 12:25:15 CDT 2016


> 
> On Apr 28, 2016, at 11:05 AM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> 
> 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?

extension NotMyType: ProtocolIdesigned {...}

extension NotMyProtocol {
     required func method1() {...}
     override required func method2() {...} // assumes NMP has already provided default
     func newThing() {...}
}

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.

-- E



More information about the swift-evolution mailing list