I want to implement next code structure:
// Base hierarchy definition
protocol A {}
protocol C {
var a: A { get set }
}
// Specific definition
protocol B: A {}
struct TestClass: C {
var a: B
}
- Protocol
C
requires variable of typeA
. - Protocol
B
was inherited fromA
. - Class
TestClass
implementsC
protocol by defining variable of typeB
(what should be ok in order of2
)
But Swift compiler complains that TestClass
doesn't conform to protocol C because Candidate has non-matching type 'B'
.
Why Swift compiler takes type B
as non-matching to type A
?