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

98 Views Asked by At

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?

1

There are 1 best solutions below

0
On

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.