0

I am woking on a new new swift 2 project using ReactiveCocoa4 and I am wondering how to observe a property change like I dit it before in ObjC.

[RACObserve(self,self.model.wifiState) subscribeNext:^(id newValue){ @strongify(self); self.wifiState = newValue; }];

Do you have any hint?

Thanks

Thierry

thierryb
  • 3,660
  • 4
  • 42
  • 58

2 Answers2

1

You can do the same using DynamicProperty:

DynamicProperty(object: self.model, keyPath: "wifiState")
    .signal // or `producer` if you care about the current value
    .map { $0 as! WifiState } // Necessary because there is no way to infer the type of the given keyPath.
    .observeNext { [unowned self] self.wifiState = $0 }
NachoSoto
  • 1,743
  • 13
  • 17
1

If you need observe data (no UI) when use MutablePropery, but if you need observe (or binding) UI so DynamicProperty

I write simple app use RAC4 for demonstration answer on more difficult after RAC2

repo github link

ajjnix
  • 462
  • 3
  • 17