Been having lots and lots of trouble with Swift protocols in combination with arrays, but I couldn\'t even reproduce my whole problem before things started to break in playgroun
I think that the problem is about the Utterable
protocol having a property, which is already implemented in the concrete class.
As you probably know, an extension cannot define stored properties (computed only). By adopting the protocol in the extension, something wrong happens - and it is clearly a bug (it should just work or the compiler should raise a compilation error).
To fix it, just adopt the protocol in the class declaration rather than to the extension:
class Bus : Displayable, Utterable { var name = "a bus"; var utterance = "this is a bus"}
extension Bus {}
Surprisingly, turning the utterance
property into a computed one and moving it in the extension body:
extension Bus : Utterable {
var utterance: String { return "this is a bus" }
}
doesn't solve the problem - still the same error. I consider it as a prove that it's a bug.