Last active
February 1, 2018 14:01
-
-
Save ibrahimkteish/a67819b19057a1e38709fc04684e4d7d to your computer and use it in GitHub Desktop.
RxSwift BehaviorSubject
This file contains 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
//disposeBag from memoy management | |
let disposeBag = DisposeBag() | |
//Create our BehaviorSubject with a string type | |
let subject = BehaviorSubject(value: "Bob") | |
//New Subscription | |
subject.subscribe { | |
print($0) | |
} | |
.addDisposableTo(disposeBag) | |
//emits | |
subject.on(.Next("Hello")) | |
subject.onNext("World") //onNext is a Convenience method equivalent to on(.Next(element: E)) | |
//New Subscription | |
let secondSubscription = subject.subscribe { | |
print("second subscription:", $0) | |
} | |
//add it to the disposeBag | |
secondSubscription.addDisposableTo(disposeBag) | |
//emit | |
subject.onNext("Ibrahim") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment