Afair I was the first to argue against this plan, and I still think the problem in question is better solved with Default implementations in protocol declarations (combined with the func Protocol.method()
idea) instead of adding a keyword.
But I think with a small yet significant change default func
could become much more useful:
extension ExampleProtocol {
// Error 1
// Error: Does not satisfy any known protocol requirement
// Fixit: replace type with Float
public default func thud(with value: Double) { ... }
}
Instead of throwing an error, we could "simply" add thud
to the official methods declared in ExampleProtocol
.
Basically, this would solve the disadvantage of to much repetition from the other direction, because obviously, you wouldn't include that method in the declaration anymore.
That alone imho still doesn't justify a change -- but there's more:
protocol Foo {
var foo: String { get }
}
protocol Bar {
var bar: String { get }
}
extension Foo where Self: Bar {
default func foobar() {
print(foo, bar)
}
}
class Foobar: Foo, Bar {
var bar: String = "bar"
var foo: String = "foo"
}
Foobar().foobar()
If we could do this (it might be rather complicated, and nothing for the near future -- we might even have extension Foo & Bar
by then ;-), we could define all kinds of functionality that is possible when some protocols are combined (maybe there's even a specific example where for that ;-)