Hello :)

Am 2016-09-23 08:50, schrieb Rien:

> -- module A --
> class A {
>   func foo() {}
> }
>
> -- module B --
> protocol Foo {
>   func foo()
> }
> extension A: Foo {}

let c = A()

I’d say that you have two functions here:
A.foo() and A.Foo.foo()

No. Now (i.e. within module B) A conforms to Foo, using the already existing function.

Note that A.foo() was never intended to be used as an implementation
for protocol Foo, thus why should you be able to see it as such? That
imo is a bug in the language. Its not flexibility, it’s dangerous.

I disagree, this is the great thing about Swift.
It's exactly in the middle between Go's "everything is considered to implement a protocol if it happens to provide the right methods" and C++/younameit's "you have to know everything in advance and people are screwed if the library does not use the right protocols" style.

You can add protocol conformance to classes you don't control, but you have to explicitly declare this conformance.
I think this is exactly the right approach.

--
Martin
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to