1

I'm trying to switch to Swift Bond 5 and Swift 3 in one of my projects. I'm having problem with two direction binding. How can I convert the code below so when my slider is changing it emits distinct signal in steps and set it's value then to the radius observable value. In old Bond 4 and Swift 2.3 everything was working fine but I don't know how to handle this kind of migration.

let radiusSlider: UISlider = /* slider initialisation */
let radius = Observable<Float>(10.0)

let stepValue:Float = 50.0
let sliderStepObserver = radiusSlider.bnd_value.map { roundf($0/stepValue)*stepValue }.distinct()
radiusSlider.value = radius.value
radius.bidirectionalBind(to: sliderStepObserver) /* here is the problem */

The error message is saying:

Argument type 'Signal<Float, DynamicSubject.Error>' (aka 'Signal<Float, NoError>') does not conform to expected type 'BindableProtocol'

So the signal is not bindable anymore. Does somebody have any ideas how to convert this piece of code so the bidirectional binding still will be working?

Marcin Kapusta
  • 5,076
  • 3
  • 38
  • 55

1 Answers1

1

Bidirectional binding to a transformed signal/observable does not really make sense because it would require inverse transformations to propagate events back.

Instead of a bidirectional binding, you probably want to establish following bindings:

radius.bind(to: radiusSlider)
sliderStepObserver.bind(to: radius)

Also, you'll need to remove that distinct operator or the stepping will not quite work. The reason it will not work is that the user never stops touching screen so we must also never stop updating the slider position to a step value.

Srđan Rašić
  • 1,597
  • 15
  • 23
  • Thank You very much for Your input. Yes it seems that this does not really make sense. The only thinks that matter in this case was to update `radius` observable with signal emitted from slider. Other direction is not needed at all. I don't know why original developer did it right that. Thanks anyway! – Marcin Kapusta Sep 23 '16 at 11:17