{"id":15050730,"url":"https://github.com/capturecontext/swift-interception","last_synced_at":"2026-02-05T12:06:18.610Z","repository":{"id":219674623,"uuid":"749601199","full_name":"CaptureContext/swift-interception","owner":"CaptureContext","description":"Package for interception of objc selectors in Swift.","archived":false,"fork":false,"pushed_at":"2024-09-28T17:38:22.000Z","size":64,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-10T07:52:46.709Z","etag":null,"topics":["interception","macros","objc","objc-runtime","objective-c","reflection","runtime","selector","selectors","swift","swift-macro","swift-macros","swift-runtime"],"latest_commit_sha":null,"homepage":"https://swiftpackageindex.com/CaptureContext/swift-interception/0.3.0/documentation/interception","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CaptureContext.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-29T02:21:58.000Z","updated_at":"2024-02-29T01:29:00.000Z","dependencies_parsed_at":"2024-02-28T02:24:45.807Z","dependency_job_id":"8285bbdc-44ad-4abe-a1e6-605b5e83b3f4","html_url":"https://github.com/CaptureContext/swift-interception","commit_stats":null,"previous_names":["capturecontext/swift-interception"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-interception","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-interception/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-interception/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CaptureContext%2Fswift-interception/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CaptureContext","download_url":"https://codeload.github.com/CaptureContext/swift-interception/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243511194,"owners_count":20302520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["interception","macros","objc","objc-runtime","objective-c","reflection","runtime","selector","selectors","swift","swift-macro","swift-macros","swift-runtime"],"created_at":"2024-09-24T21:29:08.032Z","updated_at":"2026-02-05T12:06:18.598Z","avatar_url":"https://github.com/CaptureContext.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swift-interception\n\n[![CI](https://github.com/capturecontext/swift-interception/actions/workflows/ci.yml/badge.svg)](https://github.com/capturecontext/swift-interception/actions/workflows/ci.yml) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fcapturecontext%2Fswift-interception%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/capturecontext/swift-interception) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fcapturecontext%2Fswift-interception%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/capturecontext/swift-interception)\n\nA Swift package for intercepting Objective-C selector invocations on NSObject instances, enabling observation and transformation of delegate-style APIs.\n\n## Table of contents\n\n- [Motivation](#motivation)\n- [Usage](#usage)\n  - [Basic](#basic)\n  - [Library development](#library-development)\n- [Installation](#installation)\n- [License](#license)\n\n## Motivation\n\nSeveral frameworks, including `ReactiveCocoa`, `RxCocoa`, and `CombineCocoa`, use Objective-C selector interception internally to implement delegate proxies and similar abstractions.\n\nThis package extracts a generic interception implementation from that approach and makes it available as a standalone dependency. The extracted code has been slightly generalized, supplemented with tests, and extended with a small set of ergonomic helpers for working with selectors.\n\nThe result is a small package that provides convenient tools for setting up selector interception without requiring a dependency on a larger framework.\n\n## Usage\n\n### Basic\n\nObserve selectors on NSObject instances\n\n```swift\nimport Interception\n\nnavigationController.setInterceptionHandler(\n  for: _makeMethodSelector(\n    selector: UINavigationController.popViewController,\n    signature: navigationController.popViewController\n  )\n) { result in \n  print(result.args) // `animated` flag\n  print(result.output) // popped `UIViewController?`\n}\n```\n\nYou can also simplify creating method selector with `InterceptionMacros` if you are open for macros\n\n```swift\nimport InterceptionMacros\n\nnavigationController.setInterceptionHandler(\n  for: #methodSelector(UINavigationController.popViewController)\n) { result in \n  print(result.args) // `animated` flag\n  print(result.output) // popped `UIViewController?`\n}\n```\n\n\u003e Macros require `swift-syntax` compilation, so it will affect cold compilation time\n\nYou can set up multiple interception handlers as well, just make sure that you use different keys for each handler\n\n```swift\nimport Interception\n\nobject.setInterceptionHandler(\n  for: _makeMethodSelector(\n    selector: #selector(MyObject.someMethod(arg1:arg2)),\n    signature: MyObject.someMethod(arg1:arg2)\n  ),\n  key: \"argumentsPrinter\"\n) { result in \n  // In case of multiple arguments\n  // you can access them as a tuple\n  print(result.args.0)\n  print(result.args.1)\n}\n```\n\n```swift\nimport InterceptionMacros\n\nobject.setInterceptionHandler(\n  for: #methodSelector(MyObject.someMethod(arg1:arg2)),\n  key: \"argumentsPrinter\"\n) { result in \n  // In case of multiple arguments\n  // you can access them as a tuple\n  print(result.args.0)\n  print(result.args.1)\n}\n```\n\n### Library development\n\nIf you use it to create a library it may be a good idea to export custom selectors implicitly\n\n```swift\n// Exports.swift\n@_exported import _InterceptionCustomSelectors\n```\n\nAlso you may find some `@_spi` methods and Utils helpful\n\n```swift\n@_spi(Internals) import Interception\nimport _InterceptionUtils // Is not shown in the autocomplete\n```\n\nSee [`combine-interception`](https://github.com/capturecontext/combine-interception) for usage example.\n\n## Installation\n\n### Basic\n\nYou can add Interception to an Xcode project by adding it as a package dependency.\n\n1. From the **File** menu, select **Swift Packages › Add Package Dependency…**\n2. Enter [`\"https://github.com/capturecontext/swift-interception.git\"`](https://github.com/capturecontext/swift-interception.git) into the package repository URL text field\n3. Choose products you need to link them to your project.\n\n### Recommended\n\nIf you use SwiftPM for your project, you can add Interception to your package file.\n\n```swift\n.package(\n  url: \"https://github.com/capturecontext/swift-interception.git\", \n  .upToNextMinor(from: \"0.4.0\")\n)\n```\n\nDo not forget about target dependencies:\n\n```swift\n.product(\n  name: \"Interception\", \n  package: \"swift-interception\"\n)\n```\n\n```swift\n.product(\n  name: \"InterceptionMacros\",\n  package: \"swift-interception\"\n)\n```\n\n\u003e [!NOTE]\n\u003e\n\u003e _The package is compatible with non-Apple platforms, however this package uses conditional compilation, so APIs are only available on Apple platforms_\n\n## License\n\nThis library is released under the MIT license. See [LICENSE](LICENSE) for details.\n\nSee [ACKNOWLEDGMENTS](ACKNOWLEDGMENTS) for inspiration references and their licences.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapturecontext%2Fswift-interception","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcapturecontext%2Fswift-interception","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapturecontext%2Fswift-interception/lists"}