0

I'm interested in binding a single Observable to multiple receivers. How can I achieve this concisely?

Currently, I have to resort to binding every property:

model.sectionEnabled.map{!$0}.bind(to: vc1.view.reactive.isHidden)
model.sectionEnabled.map{!$0}.bind(to: vc2.view.reactive.isHidden)
model.sectionEnabled.map{!$0}.bind(to: vc3.view.reactive.isHidden)
....

What if it would be possible to use the following construct?:

model.sectionEnabled.map{!$0}
.bind(to: vc1.view.reactive.isHidden)
.bind(to: vc2.view.reactive.isHidden)
.bind(to: vc3.view.reactive.isHidden)
.bind(to:.......

Is it already possible to do such binding with the current implementation of the framework?

chwarr
  • 6,777
  • 1
  • 30
  • 57
Richard Topchii
  • 7,075
  • 8
  • 48
  • 115

1 Answers1

1

Maybe this is what you want:

if let disabled = model.sectionEnabled.map{!$0} {
    for vc in [vc1, vc2, vc3] {
        disabled.bind(to: vc.view.reactive.isHidden)
    }
}
ielyamani
  • 17,807
  • 10
  • 55
  • 90