RACObserve does not work

I am trying to observe a property in my ViewModel and then update the label with its value using ReactiveCocoa, but it is not updating.

Here is what I got:

ViewModel

var amount: NSDecimalNumber 

ViewController

 RAC(self.amountLabel, "text") <~ RACObserve(self.viewModel, "amount").map({ (value) -> AnyObject! in let numberFormatter = NSNumberFormatter() numberFormatter.numberStyle = .CurrencyStyle return numberFormatter.stringFromNumber(value as NSDecimalNumber) }) 

I checked and ViewModel correctly updates the "amount" property. Is there something I'm missing here?

I also tried this for testing:

 RACObserve(self.viewModel, "amount").subscribeNext { (value) -> Void in println(value) } 

Does not work.

I use ReactiveCocoa 2.4.7 because my application supports iOS 7. Are there any incompatibilities between macro replacements in Swift [1,2] and this version?

[1] - https://github.com/ashfurrow/Swift-RAC-Macros

[2] - http://blog.scottlogic.com/2014/07/24/mvvm-reactivecocoa-swift.html

+7
ios reactive-cocoa
source share
1 answer

Mark the property as dynamic and make sure that the view model inherits NSObject.

 class MyViewModel: NSObject { dynamic var amount: NSDecimalNumber } 
+14
source share

All Articles