File tree Expand file tree Collapse file tree
Sources/CombineExtensions/CurrentValuePublisher Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import Foundation
2+
3+ public protocol KVOCurrentValuePublishing { }
4+
5+ extension NSObject : KVOCurrentValuePublishing { }
6+
7+ extension KVOCurrentValuePublishing where Self: NSObject {
8+
9+ /// Returns a `CurrentValuePublisher` that tracks the current value of a KVO-compliant property.
10+ ///
11+ /// - Parameter keyPath: The key path of the property to observe.
12+ /// - Returns: A `CurrentValuePublisher` that tracks the property's value.
13+ ///
14+ /// This implementation follows the approach of `NSObject.publisher(for:options:)` from Foundation,
15+ /// previously available in the [swift-corelibs-foundation](https://bit.ly/nsobject-keyvalueobserving)
16+ /// open source repository.
17+ public func currentValuePublisher< Value> (
18+ for keyPath: KeyPath < Self , Value >
19+ ) -> CurrentValuePublisher < Value , Never > {
20+ return CurrentValuePublisher (
21+ initial: self [ keyPath: keyPath] ,
22+ upstream: self . publisher ( for: keyPath, options: . new)
23+ )
24+ }
25+
26+ }
You can’t perform that action at this time.
0 commit comments