如何在协议内部初始化BehaviorRelay
protocol ArticlePresentable: Presentable {
var listener: ArticlePresentableListener? { get set }
var searchResult: BehaviorRelay<[NewsModel]> =
BehaviorRelay(value: []) { get set }
}
答案 0 :(得分:1)
您不这样做,也不应尝试。您能做的最好的事情是这样的:
protocol ArticlePresentable: Presentable {
var searchResult: BehaviorRelay<[NewsModel]> { get }
}
请注意,属性模板仅定义为{ get }
而不是{ get set }
,因为您永远都不要重置行为中继。