如何在协议内部初始化BehaviorRelay

时间:2019-12-22 08:35:55

标签: swift rx-swift

如何在协议内部初始化BehaviorRelay

protocol ArticlePresentable: Presentable {
  var listener: ArticlePresentableListener? { get set }

  var searchResult: BehaviorRelay<[NewsModel]> =
    BehaviorRelay(value: []) { get set }
}

1 个答案:

答案 0 :(得分:1)

您不这样做,也不应尝试。您能做的最好的事情是这样的:

protocol ArticlePresentable: Presentable {
    var searchResult: BehaviorRelay<[NewsModel]> { get }
}

请注意,属性模板仅定义为{ get }而不是{ get set },因为您永远都不要重置行为中继。