I came across the following code and am not sure why it doesn’t compile:
protocol CellDelegate: class {}
protocol DelegatingCellViewModel {
var delegate: CellDelegate? { get }
}
protocol ProductCellViewModelDelegate: CellDelegate {}
// Error: Type 'ProductCellViewModel' does not conform to protocol 'DelegatingCellViewModel'
class ProductCellViewModel: DelegatingCellViewModel {
weak var delegate: ProductCellViewModelDelegate?
}
Full error message:
error: Playground.playground:9:7: error: type 'ProductCellViewModel' does not conform to protocol 'DelegatingCellViewModel'
class ProductCellViewModel: DelegatingCellViewModel {
^
Playground.playground:10:14: note: candidate has non-matching type 'ProductCellViewModelDelegate?'
weak var delegate: ProductCellViewModelDelegate?
^
Playground.playground:4:9: note: protocol requires property 'delegate' with type 'CellDelegate?'; do you want to add a stub?
var delegate: CellDelegate? { get }
^
Is this a language limitation or am I missing something? How should this code be written so it compiles and keeps the intent?