Last active
September 28, 2016 07:10
-
-
Save ibrahimkteish/6253f22e5cb91358d43858660f54459c to your computer and use it in GitHub Desktop.
RxSwift ReplaySubject type
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 ReplaySubject with a string type | |
let subject = ReplaySubject<String>.create(bufferSize: 2) | |
subject.on(.Next("A")) | |
//New Subscription | |
subject.subscribe { | |
print($0) | |
} | |
.addDisposableTo(disposeBag) | |
//emits | |
subject.on(.Next("B")) | |
subject.onNext("C") //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("D") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment