-
-
Save minsOne/bd63e5111c3f556e25a345916b0dffb3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import RxSwift | |
| import RxCocoa | |
| @dynamicMemberLookup | |
| protocol DynamicMemberLookupableObservableType: AssociateObservable { | |
| subscript<T>(dynamicMember keyPath: KeyPath<Value, T>) -> Observable<T> { get } | |
| } | |
| extension DynamicMemberLookupableObservableType { | |
| subscript<T>(dynamicMember keyPath: KeyPath<Value, T>) -> Observable<T> { | |
| self.myself.map({ $0[keyPath: keyPath] }) | |
| } | |
| } | |
| extension Observable: DynamicMemberLookupableObservableType { } | |
| @dynamicMemberLookup | |
| protocol DynamicMemberLookupableBinder { | |
| associatedtype Element | |
| subscript<T>(dynamicMember keyPath: ReferenceWritableKeyPath<Element, T>) -> Binder<T> { get } | |
| } | |
| extension Reactive: DynamicMemberLookupableBinder where Base: AnyObject { | |
| typealias Element = Base | |
| subscript<T>(dynamicMember keyPath: ReferenceWritableKeyPath<Element, T>) -> Binder<T> { | |
| Binder(self.base) { base, value in | |
| base[keyPath: keyPath] = value | |
| } | |
| } | |
| } | |
| // usage | |
| Observable.just("ABC").first // Observable<Character?> | |
| SomeButton.rx.isHighlighted // Binder<Bool> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment