1

I'm trying to migrate my project to Swift 3. I am using ReactiveKit and Bond and I am struggling with some conversions.

1) Most of my extensions used to look like this:

extension UIView {

public var bnd_superview: Observable<UIView?> {
    return bnd_associatedObservableForValueForKey("superview")
}

I can't find what bnd_associatedObservableForValueForKey was changed to.

2) I have the following code:

self.myButton.bnd_selected.next(false)

it should change to:

self.myButton.reactive.isSelected.next(false)

but I get the following error:

Value of type 'Bond' has no member 'next'

chwarr
  • 6,777
  • 1
  • 30
  • 57
Or Chen
  • 33
  • 4

1 Answers1

0

First one can be replaced by Bond type. You can also do it as a ReactiveExtensions extension instead as a UIView extension, so you get .reactive prefix.

extension ReactiveExtensions where Base: UIView {

    public var superview: Bond<UIView?> {
        return bond { view, superview in
            view.superview = superview
        }
    }
}

You can then bind a signal to your bond.

let view: SafeSignal<UIView> = ...
view.bind(to: someView.reactive.superview)

Bonds cannot be observed though, just like there is no way to observe UIView.superview. KVO might work, but UIKit is not KVO compliant.

As for the second question, isSelected is of type Bond and yes, it does not have the method next. It is used to bind signals.

You should just do:

self.myButton.isSelected = false

Srđan Rašić
  • 1,597
  • 15
  • 23
  • I have many uses for .next in my app. Most of them are not for Bool's. Is there any extension I can use to add .next to Bond? – Or Chen Mar 15 '17 at 09:52
  • You could do `SafeSignal.just("abc").bind(to: textField.reactive.text)` and you could pull that into an extension if you really wanted to. – Srđan Rašić Mar 15 '17 at 13:16