If that PR is merged, it will add functionality to CombineCocoa.
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
TL;DR
import UIKit
import Combine
import CombineInterception
extension UIViewController {
var viewDidLoadPublisher: AnyPublisher<Void, Never> {
let selector = #selector(UIViewController.viewDidLoad)
return publisher(for: selector)
.map { _ in () }
.eraseToAnyPublisher()
}
var viewWillAppearPublisher: AnyPublisher<Bool, Never> {
let selector = #selector(UIViewController.viewWillAppear(_:))
return intercept(selector)
.map { $0[0] as? Bool ?? false }
.eraseToAnyPublisher()
}
}
class ViewController: UIViewController {
private var subscriptions = Set<AnyCancellable>()
private func bind() {
viewDidLoadPublisher
.sink(receiveValue: { _ in
print("viewDidLoad")
})
.store(in: &subscriptions)
viewWillAppearPublisher
.sink(receiveValue: { isAnimated in
print("viewWillAppearPublisher", isAnimated)
})
.store(in: &subscriptions)
}
}
This project has the following dependencies:
- Combine.framework
Add the following dependency to your Package.swift file:
.package(url: "https://github.com/chorim/CombineInterception.git", from: "0.1.0")
- CombineInterception was created by referencing https://github.com/EduDo-Inc/CombineCocoa
MIT, See the LICENSE file.
The Combine framework are property of Apple Inc.