I'm trying to observe a property in my ViewModel, and then update a label with it's value using ReactiveCocoa, but it's not updating.
Here's 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 the ViewModel is updating the 'amount' property correctly. Is there anything I'm missing here?
I also tried this for testing:
RACObserve(self.viewModel, "amount").subscribeNext {
(value) -> Void in
println(value)
}
Doesn't work either.
I'm using ReactiveCocoa 2.4.7 because my app is supporting iOS 7. Are there any incompatibilities between the 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
Mark the property as dynamic
, and make sure the view model inherits NSObject.
class MyViewModel: NSObject {
dynamic var amount: NSDecimalNumber
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With