Rxswift: Multiple Buttons Single Action

Created on 1 Feb 2017  路  5Comments  路  Source: ReactiveX/RxSwift

how can i handle action of multiple button by combining them in RxSwift?

Most helpful comment

Hi, @Rico9260

Just merge them into one sequence e.g:

let o = Observable.of(button1.rx.tap, button2.rx.tap).merge()

All 5 comments

Hi, @Rico9260

Just merge them into one sequence e.g:

let o = Observable.of(button1.rx.tap, button2.rx.tap).merge()

i need to access the tag of button inside the subscribe call

let o = Observable.of(button1.rx.tap, button2.rx.tap).merge()

o.subscribe(onNext: {
//tag of button that is clicked
})

let tag1 = button1.rx.tap.map { [unowned self]  _ in return self.button1.tag}
let tag2 = button2.rx.tap.map { [unowned self]  _ in return self.button2.tag}
let tags = Observable.of(tag1, tag2).merge()

I think we can close this one 馃榾

I have five buttons in VC and four buttons maintains isSelected property
if either of the four button's isSelected is true I need to show the fifth button
otherwise i Need to hide it.

How can I achieve this ?

Was this page helpful?
0 / 5 - 0 ratings