iOS Swift Combine: cancel a Set

后端 未结 5 2114
醉梦人生
醉梦人生 2021-01-11 09:52

If I have stored a cancellable set into a ViewController:

private var bag = Set()

Which contains multiple subscription.

5条回答
  •  无人及你
    2021-01-11 10:19

    Try creating a pipeline and not storing the cancellable in some state variable. You’ll find that the pipeline stops as soon as it encounters an async operation. That’s because the Cancellable was cleaned up by ARC and it was thus automatically cancelled. So you don’t need to call cancel on a pipeline if you release all references to it.

    From the documentation:

    An AnyCancellable instance automatically calls cancel() when deinitialized.

提交回复
热议问题