Skip to content

Commit

Permalink
Add KVO Publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
srdanrasic committed Feb 6, 2020
1 parent f1fddae commit ca6619a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ReactiveKit.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pod::Spec.new do |s|
s.name = "ReactiveKit"
s.version = "3.16.1"
s.version = "3.16.2"
s.summary = "A Swift Reactive Programming Framework"
s.description = "ReactiveKit is a Swift framework for reactive and functional reactive programming."
s.homepage = "https://github.com/DeclarativeHub/ReactiveKit"
s.license = 'MIT'
s.author = { "Srdan Rasic" => "[email protected]" }
s.source = { :git => "https://github.com/DeclarativeHub/ReactiveKit.git", :tag => "v3.16.1" }
s.source = { :git => "https://github.com/DeclarativeHub/ReactiveKit.git", :tag => "v3.16.2" }

s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.11'
Expand Down
4 changes: 2 additions & 2 deletions ReactiveKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MARKETING_VERSION = 3.16.1;
MARKETING_VERSION = 3.16.2;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -1096,7 +1096,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MARKETING_VERSION = 3.16.1;
MARKETING_VERSION = 3.16.2;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 4.0;
Expand Down
23 changes: 23 additions & 0 deletions Sources/Reactive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@ extension ReactiveExtensions where Base: NSObject {
public var bag: DisposeBag {
return base.bag
}

/// Create a Signal that establishes a key-value observation of the given key path when observed.
///
/// For example:
///
/// let player = AVPlayer()
/// player.reactive.publisher(for: \.status).sink { print("Playback status: \($0)") }
///
public func publisher<Value>(for keyPath: KeyPath<Base, Value>, options: NSKeyValueObservingOptions = [.initial, .new]) -> Signal<Value, Never> {
return Signal { [weak base] observer in
guard let base = base else {
observer.receive(completion: .finished)
return SimpleDisposable(isDisposed: true)
}
let observation = base.observe(keyPath, options: options) { (base, change) in
observer.receive(base[keyPath: keyPath])
}
return BlockDisposable {
observation.invalidate()
}
}
}
}


#endif

0 comments on commit ca6619a

Please sign in to comment.