Skip to content

Instantly share code, notes, and snippets.

@deda9
Last active June 18, 2019 08:26
Show Gist options
  • Save deda9/705a4a8a240cf7199d6106d886eb3a1d to your computer and use it in GitHub Desktop.
Save deda9/705a4a8a240cf7199d6106d886eb3a1d to your computer and use it in GitHub Desktop.
Create RxObservable with create
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