Step into Swift logo

What is a BehaviorSubject in RxSwift?

BehaviorSubject

RxSwift: BehaviorSubject

  • Similar to a PublishSubject except, it will replay the latest .next event to new subscribers.
  • Needs a initial value upon creation - If you can’t think of one use a PublishSubject
  • Starts with an initial value and replays it or the latest element to new subscribers.
  • Useful when you want to repopulate a view with the most recent data.
let subject = BehaviorSubject<String>(value: "8 in a row!")

< All Posts