Created
August 17, 2016 00:22
-
-
Save mingyeow/a15b291022e5b90f8e221d3bb3ed237b to your computer and use it in GitHub Desktop.
FeedNextInto For RxSwift
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 Foundation | |
extension ObservableType { | |
func feedNextInto(variable: Variable<E>) -> Observable<E> { | |
return Observable<E>.create{ observer -> Disposable in | |
self.subscribe( | |
onNext: { | |
variable.value = $0 | |
observer.onNext($0) | |
}, | |
onError: { observer.onError($0)}, | |
onCompleted: {observer.onCompleted()} | |
) | |
return NopDisposable.instance | |
} | |
} | |
} | |
let o = Observable.just(999) | |
let v = Variable(0) | |
let db = DisposeBag() | |
v.asObservable() | |
.subscribeNext{print ("Variable Value: \($0)")} | |
o | |
.feedNextInto(v) | |
.subscribeCompleted{print ("Observable: Completed")} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment