目录

Cancellor

Bind multiple cancellables to the lifetime of another object like your view controller.

Usage

Import Cancellor and subscribe your publishers inside an ownedCancellables block. When your view controller is dismissed any active subscriptions will get cancelled automatically.

import Cancellor

class MyViewController: UIViewController {
  override func viewDidLoad() {
    ownedCancellables {
      myPublisher1.sink(...)
      myPublisher2.sink(...)
      myPublisher3.assign(to: ..., on: ...)
    }
  }
}

To tie a single subscription to the lifetime of another object use:

class ViewModel: NSObject { ... }
let vm = ViewModel(...)

...

myPublisher
  .sink(...)
  .owned(by: vm)

Import

Add the following dependency to your Package.swift file:

.package(url: "https://github.com/icanzilb/Cancellor", from: "0.2.0")

License

Cancellor is available under the MIT license. See the LICENSE file for more info.

Credits

Created by Marin Todorov.

📚 You can support me by checking out our Combine book: combinebook.com.

Inspired by Ash Furrow’s NSObject-rx.

Name by https://github.com/manmal.

关于
36.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802032778号