简体   繁体   中英

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,

use take(1) operator

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM