gpt4 book ai didi

swift - 无法使用另一个符合协议(protocol)的协议(protocol)来符合协议(protocol)

转载 作者:搜寻专家 更新时间:2023-11-01 05:32:07 31 4
gpt4 key购买 nike

<分区>

我遇到了以下代码,但不确定为什么它无法编译:

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?
}

完整错误信息:

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 }
^

这是语言限制还是我遗漏了什么?应该如何编写此代码才能编译并保持意图?

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com