Cancellor

0.2.0

Bind multiple cancellables to the lifetime of another object like a view controller.
icanzilb/Cancellor

What's New

Cancellor 0.2.0

2021-02-04T19:33:58Z

Adding methods to handle single subscriptions

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.

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

  • None
Last updated: Mon Oct 21 2024 17:07:49 GMT-0900 (Hawaii-Aleutian Daylight Time)