Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/icanzilb/cancellor

Bind multiple cancellables to the lifetime of another object like a view controller.
https://github.com/icanzilb/cancellor

combine-framework reactive-programming swift

Last synced: 1 day ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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.

```swift
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:

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

...

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

## Import

Add the following dependency to your **Package.swift** file:

```swift
.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](http://combinebook.com).

Inspired by Ash Furrow's [NSObject-rx](https://github.com/RxSwiftCommunity/NSObject-Rx).

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