sách gpt4 ăn đã đi

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

In lại 作者:搜寻专家 更新时间:2023-11-01 05:32:07 32 4
mua khóa gpt4 giày 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 }
^

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

32 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress