I'm trying to embrace Protocol-Oriented Design, so I've started experimenting with building my architecture using a set of "base classes" implemented as protocols. But I'm not getting very far... What I keep getting stuck on is type mismatches when I try to connect together objects that conform to my "base class" protocols.
Here's a simple example?
protocol TypeA {
var typeB: TypeB { get set }
}
protocol TypeB {
}
struct structTypeB: TypeB {
func doSomethingAwesome() {}
}
struct structTypeA: TypeA {
var typeB: TypeB
}
let sTypeB = structTypeB() // <--- this implements doSomethingAwesome()
let sTypeA = structTypeA(typeB: sTypeB)
sTypeA.typeB.doSomethingAwesome() // <--- error! "no member doSomethignAwesome()"In fact, the Playground initially seems to think sTypeA.typeB is actually structTypeB, but option-clicking reveals that it's actually not... This, of course, is confirmed by the fact that I can't access the doSomethingAwesome() function.
So, how can I get structTypeA to accept/implement it's "typeB" property as a "structTypeB" (or something conforming to the TypeB protocol)?
Any help greatly appreciated.
J.