The described problem might be one of the most famous itches of the language,
but imho the bar for new keywords* should be higher than that — and there are
alternatives:
First, I guess many would like to see this to be valid Swift:
protocol Foo {
func bar() {
print("Default implementation called")
}
}
It's the most convenient way of avoiding typos: avoid to type ;-)
Imho this might already be enough, but for a full alternative for "default",
I'd suggest something like this:
extension Foo {
func Foo.bar() {
print("String has its own implementation")
}
}
(to make it more familiar for those with a C++ background, "Foo::bar" could be
used instead ;-)
Additional benefit: This wouldn't be limited to protocols — and it could
possibly help in weird situations when two protocols declare functions with
identical signature...
extension String: Foo {
func Foo.bar() {
print("String has its own implementation")
}
func Foo.barr() {
// compiler error, Foo defines no function "barr"
}
func barr() {
// this is fine, no connection to a protocol
}
}
- Tino
* well, I guess "default" is not really a new keyword… but you get the point
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution