Rxswift What difference between Observable.of and Observable<String>.create

折月煮酒 提交于 2019-12-06 13:13:59

The main difference is that of sends a completed event as well. You can check the example below, the second "completed" will not be called.

You have to write observer.onCompleted() after observer.onNext("2") it order to have the same logic.

Observable.of("1", "2").subscribe(onCompleted: {
    print("completed")
})

Observable<String>.create { observer in
        observer.onNext("1")
        observer.onNext("2")
        return Disposables.create()
    }
    .subscribe(onCompleted: {
        print("completed")
    })
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!