Last active
June 18, 2019 08:26
-
-
Save deda9/705a4a8a240cf7199d6106d886eb3a1d to your computer and use it in GitHub Desktop.
Create RxObservable with create
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
func createRxObservable() { | |
let source: Observable<Int> = Observable.create { observer in | |
for i in 1...5 { | |
observer.on(.next(i)) | |
} | |
observer.on(.completed) | |
return Disposables.create() | |
} | |
source | |
.subscribe(onNext: { number in | |
print("Current emitted number: ", number) | |
}, onError: nil, | |
onCompleted: { | |
print("Complete") | |
}, onDisposed: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment