User17373928
User17373928

Reputation: 29

Can I pause data stream by a flag with RxSwift?

First of all, here is my code

viewModel.price
            .drive(collectionView.rx.items(cellIdentifier: "Cell")) { (index: Int, Info, cell: Cell) in 
                 ....
          }.disposed(by: disposeBag)

viewModel.price's data type is Driver<[Info]>

In this code, I want to add a flag which is for pausing collectionView.
When the flag from viewModel is "true" then keep drawing collectionView but if it's "false" then stop it.

I think I need to use combineLatest and takeWhile but not sure how to use this.

how can I use combineLatest and takeWhile for my code?

Upvotes: 0

Views: 425

Answers (1)

hell0friend
hell0friend

Reputation: 569

Try this:

Driver.combineLatest(viewModel.price, viewModel.shouldDraw)
    .filter { $1 }
    .map { $0.0 }
    .drive(collectionView.rx.items(cellIdentifier: "Cell")) { (index: Int, Info, cell: Cell) in 
             ....
    }.disposed(by: disposeBag)

Upvotes: 2

Related Questions