Swiftpack.co - chorim/CombineInterception as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by chorim.
chorim/CombineInterception 0.1.1
Allowing you to subscribe to the invocation of Objective-C methods.
⭐️ 8
🕓 36 weeks ago
iOS macOS
.package(url: "https://github.com/chorim/CombineInterception.git", from: "0.1.1")

CombineInterception

WARNING

If that PR 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

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)
    }
}

Dependencies

This project has the following dependencies:

  • Combine.framework

Installation

Swift Package Manager

Add the following dependency to your Package.swift file:

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

Acknowledgments

License

MIT, See the LICENSE file.

The Combine framework are property of Apple Inc.

GitHub

link
Stars: 8
Last commit: 6 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Update Package.swift
36 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics