[First of all if someone has a better name for the question, proposal are well accepted. I didn't find a better name for this question so far.]
So, that's the question.
Assuming I have a protocol ProtocolA
, a protocol ProtocolB
and a protocol ProtocolX
defined as following:
protocol ProtocolA {
func doSomethingA()
}
protocol ProtocolB {
func doSomethingB()
}
protocol ProtocolX {
var handler: ProtocolA { get }
}
Then I have a proper implementation in a class of my ProtocolX as following:
class Donald: ProtocolX {
...
var handler: ProtocolA { ... }
...
}
Then everything is ok and the protocol requirement is correctly fulfilled.
BUT
If I implement like that:
class Donald: ProtocolX {
...
var handler: ProtocolA & ProtocolB
...
}
I have a compile-time issue reporting that my class Donald
does not conform to ProtocolX
(that, by specification, requires that the var handler
must be conform to ProtocolA
).
Theoretically the var handler
IS conform to ProtocolA
(but it's also conform to ProtocolB
).
Then my question is: Why the compile-time issue? Swift limitation or conceptual issue on my side?