So I'm constructing a Foo object and this concrete Foo object has a bar2 which is a Bar. That bar complies with the BarProt protocol, but still it's not recognized. What can I do about this? I need the var2 to be compliant with Bar in this case.
For the reason why: I have many kinds of Bar that slightly differ and I tried to find the lowest common denominator which I extracted into BarProt, so I could reuse the logic for handling Bar-like objects .
(I'm basically making various lookups based on the properties of the bar objects, and want to make a general resolver for a BarProt and then handle the specifics elsewhere).
protocol BarProt {
var bar: String {get}
}
struct Bar: BarProt {
var bar: String
}
protocol FooProt {
var var1: String {get}
var var2: BarProt {get}
}
struct Foo: FooProt {
let var1: String
let var2: Bar // I'm required to change it to BarType, but I really don't want to, since Bar contains so much more that BarType
}
let barInstance = Bar(bar: "Hello")
print(Foo(var1: "String", var2: barInstance))
And the error:
protocol requires property 'var2' with type 'BarProt'; do you want to add a stub?
var var2: BarProt