Joakim Sjöstedt
Joakim Sjöstedt

Reputation: 948

How do I bind an Rx Bool to selectedSegmentIndex of a SegmentedController?

I have an rx observable returning a Bool that I need to bind to a SegmentedControl's selectedSegmentIndex. The function looks like this:

func getLockPower() -> Observable<Bool> {
    do {
        return try doorModeService.getDoorLockPower().map { $0.rawValue == 1 }.asObservable()
    } catch {
        return .error(error)
    }
}

And I have tried binding it to my SegementedControl like this:

lockViewModel.getLockPower()
             .bind(to: lockInstalledSegmentController.rx.selectedSegmentIndex)
             .disposed(by: disposeBag)

But I get the error:

No exact matches in call to instance method 'bind'

I don't think I get the syntax, and I haven't been able to find any source on how it should look like. Any suggestions?

Upvotes: 0

Views: 114

Answers (1)

Joakim Sj&#246;stedt
Joakim Sj&#246;stedt

Reputation: 948

Alright, I worked it out. The index obviously need an Int, so instead of mapping to Bool I mapped to an Int and it worked.

Upvotes: 0

Related Questions