Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/chorim/combineinterception

Allowing you to subscribe to the invocation of Objective-C methods.
https://github.com/chorim/combineinterception

combine ios objective-c rxswift swift

Last synced: 2 months ago
JSON representation

Allowing you to subscribe to the invocation of Objective-C methods.

Awesome Lists containing this project

README

        

# CombineInterception

## WARNING
### If that [PR](https://github.com/CombineCommunity/CombineCocoa/pull/88) is merged, it will add functionality to CombineCocoa.
### Please use CombineCocoa in future.

##


CombineCocoa supports Swift Package Manager (SPM)

CombineInterception is a library that provides functionality similar to the methodInvoked function from RxCocoa, allowing you to subscribe to the invocation of Objective-C methods.

Reference from https://github.com/EduDo-Inc/CombineCocoa

## Usage
TL;DR

```swift
import UIKit
import Combine
import CombineInterception

extension UIViewController {
var viewDidLoadPublisher: AnyPublisher {
let selector = #selector(UIViewController.viewDidLoad)
return publisher(for: selector)
.map { _ in () }
.eraseToAnyPublisher()
}

var viewWillAppearPublisher: AnyPublisher {
let selector = #selector(UIViewController.viewWillAppear(_:))
return intercept(selector)
.map { $0[0] as? Bool ?? false }
.eraseToAnyPublisher()
}
}

class ViewController: UIViewController {
private var subscriptions = Set()

private func bind() {
viewDidLoadPublisher
.sink(receiveValue: { _ in
print("viewDidLoad")
})
.store(in: &subscriptions)

viewWillAppearPublisher
.sink(receiveValue: { isAnimated in
print("viewWillAppearPublisher", isAnimated)
})
.store(in: &subscriptions)
}
}
```

## Dependencies

This project has the following dependencies:

* Combine.framework

## Installation

### Swift Package Manager

Add the following dependency to your Package.swift file:

```swift
.package(url: "https://github.com/chorim/CombineInterception.git", from: "0.1.0")
```

## Acknowledgments

* CombineInterception was created by referencing https://github.com/EduDo-Inc/CombineCocoa

## License

MIT, See the [LICENSE](LICENSE) file.

The Combine framework are property of Apple Inc.