'How can I read the value of an RxSwift property? <Driver>Bool

I'd like to read the value of a property

var checkInEnabled: Driver<Bool> { get }

I only need to to run a bit code once when the class has loaded, so I don't want to use something like:

roomStatus.checkInEnabled
      .drive { [weak self] enabled in
        if !enabled {
          // do something everytime it changes
        }
      }.disposed(by: disposeBag)

But rather something like this:

if roomStatus.checkInEnabled {
//only do something now
}

Thanks for reading,



Solution 1:[1]

use take(1) operator

roomStatus.checkInEnabled
      .take(1)
      .drive { [weak self] enabled in
        if !enabled {
           // ~~~
        }
      }.disposed(by: disposeBag)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SEUNGHWAN LEE