Reputation: 9693
I'm new to ReactiveCocoa and would like to use it as a replacement for KVO on some NSManagedObject
s in a Swift 2 project.
Most of the examples I found online use RACObserve()
, which has been removed(?) in RAC 3. The Changelog states, that the new versions de-emphesize KVO and I should move to PropertyType
s.
Is there any way that I can use Reactive Cocoa 3 and 4 on an existing NSManagedObject
in a similar way to what could be done with RACObserve()
?
Upvotes: 3
Views: 769
Reputation: 815
ReactiveCocoa 3.0 documentation points to the DynamicProperty
The DynamicProperty type can be used to bridge to Objective-C APIs that require Key-Value Coding (KVC) or Key-Value Observing (KVO), like NSOperation. Note that most AppKit and UIKit properties do not support KVO, so their changes should be observed through other mechanisms. MutableProperty should be preferred over dynamic properties whenever possible!
So you need to make an DynamicProperty object and use it's signalProducer. Something like this:
DynamicProperty(object: managedObject, keyPath: "attribute").producer
P. S. ReactiveCocoa source code has awesome inline documentation. Checkout out it for more information.
Upvotes: 6