I'd like to be able to write the following code:
protocol Named {
var name: String { get }
}
struct Model: Named {
var name: String
}
@dynamicMemberLookup
struct WrappedModel: Named {
var model: Model
subscript<T>(dynamicMember keyPath: KeyPath<Model, T>) -> T {
return model[keyPath: keyPath]
}
}
let wrapper = WrappedModel(model: Model(name: "cocoafrog"))
However, on the line WrappedModel: Named
I get a compiler error
Type 'WrappedModel' does not conform to protocol 'Named'
I don't fully understand why this is not possible. After all, after the above code, I can access a name
property of type String
on the variable wrappedModel
:
wrappedModel.name
Why does the protocol conformance fail in this case? Is this an intentional limitation or a bug?