Search code examples
iosobjective-cswiftreactive-programmingreactive-cocoa

How to bind from Swift view model to Obj-c view controller?


I'm using ReactiveCocoa 4.1.0, and I'm interfacing a (new) Swift view model with a (legacy) Obj-c view controller. I'm having issues using RACObserve to observe String properties from the view model. I can't use MutableProperty because the view controller is in Obj-c. The RACObserve subscribeNext's fire once upon first setting the properties, but after changing them, no signal seems to fire. I have basically:

In View Controller:

[RACObserve(self.viewModel, buttonTitle) subscribeNext:^(NSString *title) {
    // Do something
    }];

In View Model:

init() {
   self.buttonTitle = "Original Value"
}
func foo() {
   self.buttonTitle = "Changed Value"
}

I see a fire for the original value, but never the changed value, even after putting the change in a Signal Producer and observing using observeOn(UIScheduler()).start()

Any ideas?

Thanks!


Solution

  • You need to be sure that any property observable through KVO is marked as being dynamic.