Kevin Pham
Kevin Pham

Reputation: 19

How to initialize BehaviorRelay inside of protocol

How to initialize BehaviorRelay inside of protocol

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

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

Upvotes: 1

Views: 480

Answers (1)

Daniel T.
Daniel T.

Reputation: 33979

You don't, nor should you try. The best you can do is something like this:

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

Note that the property template is only defined as a { get } rather than { get set } because you should never reset a behavior relay.

Upvotes: 3

Related Questions