combine-interception

0.3.0

Package extending Apple' `Combine` framework for interception of objc selectors.
CaptureContext/combine-interception

What's New

0.3.0

2024-02-28T03:10:59Z

What's Changed

  • feat: Add macros from combine-interception-macros package by @maximkrouk in #2

Full Changelog: 0.2.1...0.3.0

combine-interception

CI SwiftPM 5.9 Platforms @capturecontext

Combine API for interception of objc selectors in Swift.

Usage

Basic

Observe selectors on NSObject instances

navigationController.intercept(_makeMethodSelector(
  selector: UINavigationController.popViewController,
  signature: navigationController.popViewController
))
.sink { result in
  print(result.args) // `animated` flag
  print(result.output) // popped `UIViewController?`
}

You can also simplify creating method selector with CombineInterceptionMacros if you are open for macros

navigationController.intercept(
  #methodSelector(UINavigationController.popViewController)
).sink { result in
  print(result.args) // `animated` flag
  print(result.output) // popped `UIViewController?`
}

Macros require swift-syntax compilation, so it will affect cold compilation time

Library

If you use it to create a library it may be a good idea to export this one implicitly

// Exports.swift
@_exported import CombineInterception

It's a good idea to add a separate macros target to your library as well

// Exports.swift
@_exported import CombineInterceptionMacros

Installation

Basic

You can add CombineInterception to an Xcode project by adding it as a package dependency.

  1. From the File menu, select Swift Packages › Add Package Dependency…
  2. Enter "https://github.com/capturecontext/combine-interception.git" into the package repository URL text field
  3. Choose products you need to link them to your project.

Recommended

If you use SwiftPM for your project, you can add CombineInterception to your package file.

.package(
  url: "https://github.com/capturecontext/combine-interception.git", 
  .upToNextMinor(from: "0.3.0")
)

Do not forget about target dependencies:

.product(
  name: "CombineInterception", 
  package: "combine-interception"
)
.product(
  name: "CombineInterceptionMacros",
  package: "combine-interception"
)

License

This library is released under the MIT license. See LICENCE for details.

See ACKNOWLEDGMENTS for inspiration references and their licences.

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Mon Oct 21 2024 04:08:53 GMT-0900 (Hawaii-Aleutian Daylight Time)