When should we call addDisposableTo(disposeBag) in RxSwift?

前端 未结 2 1053
故里飘歌
故里飘歌 2021-02-19 19:47

We create a DisposeBag, and a Observable, subscribe the Observable and then addDisposableTo(disposeBag), I know when the

2条回答
  •  独厮守ぢ
    2021-02-19 19:55

    If you are certain that the observable completes in a deterministic way - like using just in your example, or using take, takeUntil, etc. -, you may choose to not use the DisposeBag.

    You might get a compiler warning, that actually explains this behavior well and how to work around it. But in general, it is more future-proof if you use DisposeBag anyway.

    See: Unused disposable warning

提交回复
热议问题