5

I have a UISwitch that needs to be selected in order to continue onto the next form screen. So I would like to bind the UISwitch selected to the UIButton enabled. I just can't get this sample going.

Here's what I'm trying but doesn't compile:

let termsValidation = termsSwitch
    .rx_selected
    .shareReplay(1)

termsValidation
    .bindTo(signupButton.rx_enabled)
    .addDisposableTo(disposeBag)

What's the correct way to get this to work in RxSwift and RxCocoa?

solidcell
  • 7,639
  • 4
  • 40
  • 59
TruMan1
  • 33,665
  • 59
  • 184
  • 335

2 Answers2

7

You should use rx_value rather than rx_selected.

mrahmiao
  • 1,291
  • 1
  • 10
  • 22
5
    let termsValidation = termsSwitch
            .rx.value
            .shareReplay(1)

    termsValidation
        .bind(to: signupButton.rx.isEnabled)
        .addDisposableTo(disposeBag)
Kashif Jilani
  • 1,207
  • 3
  • 22
  • 49