Multiple protocol inheritance in Swift 2.0 using extension protocols

425 Views Asked by At

Playing with the new extension protocols in Swift 2.0 come by this example:

protocol A {
  func foo()
}

protocol B {
  func foo()
}

extension A {
    func foo() { print("A") }
}

extension B {
    func foo() { print("B") }
}

class C: A, B {

}

Is something like a "multiple inheritance" , that some languages like Python and C++ can handle as multiple inheritance of course. What really surprise me was the two compile errors that Xcode 7.0 Beta 4 gave me:

Type 'C' does not conform to protocol 'A'


Type 'C' does not conform to protocol 'B'

But this error not make any sense because the error must reflect that exist conflict or ambiguity between protocol A and B regarding the use of the foo function, or something like that.

If you put below of the above code the following line :

C().foo()

This launches exactly the error type I talking about:

Ambiguous use of 'foo'

My question here is :

With the new addition of extension protocols in Swift 2.0 has Apple considered any treatment to this kind of "multiple inheritance"(something like the way of C++ treatment) or just is not allowed at all?

0

There are 0 best solutions below