RxObserve is an extension that allows you to use observe with keypath.
class SomeObject: NSObject {
@objc dynamic var text: String = ""
}
let object = SomeObject()
// in RxCocoa observe, Optional type and must be typed and is a string keypath.
let textObservable = object.rx.observe(String.self, "text") // observe in RxCocoa, It's type is Observable<String?>
// RxObserve
let textObservable = object.rx.asObservable(keyPath: \.text) // It's type is Observable<String>
let textObservable = object.rx.asObservable(keyPath: \.text, options: [.new]) // default value for options is [.initial, .new]
let textObserver = object.rx.asObserver(keyPath: \.text) // It's type is AnyObserver<String>
let view = UIView()
let backgroundColorObservable = view.rx.asObservable(keyPath: \.backgroundColor) // It's type is Observable<UIColor?>
To run the example project, clone the repo, and run pod install
from the Example directory first.
RxObserve is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'RxObserve'
kjisoo, [email protected]
RxObserve is available under the MIT license. See the LICENSE file for more info.