You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README-legacy.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,3 @@
1
-
Instead of [adding new methods and exchanging implementations](https://nshipster.com/method-swizzling/) based on [`method_exchangeImplementations`](https://developer.apple.com/documentation/objectivec/1418769-method_exchangeimplementations), this library replaces the implementation directly using [`class_replaceMethod`](https://developer.apple.com/documentation/objectivec/1418677-class_replacemethod). This avoids some of [the usual problems with swizzling](https://pspdfkit.com/blog/2019/swizzling-in-swift/).
2
-
3
1
## Usage
4
2
5
3
Let's say you want to amend `sayHi` from `TestClass`:
**InterposeKit** is a modern library for hooking Objective-C methods in Swift, also known as method swizzling. It supports both class-based and object-based hooks and it provides a clean, block-based, Swift-friendly API.
6
6
7
7
This is a continuation and modernization of [Peter Steinberger’s original implementation](https://github.com/steipete/InterposeKit). For the background on why and how this revamp came about, see [my blog post](#). If you’re migrating, check out [what’s changed](#).
8
8
9
9
## Key Features
10
10
11
-
- Swift-friendly, minimal, thread-safe API.
11
+
- Swift-friendly, modern, and minimal API.
12
12
- Block-based hooks targeting both classes and individual objects.
13
13
- Support for both instance and class methods.
14
14
- Hooks get access to the original implementation via a proxy.
@@ -19,12 +19,25 @@ This is a continuation and modernization of [Peter Steinberger’s original impl
19
19
- There’s no runtime type checking, and the signature has to be written twice—a trade-off to avoid `NSInvocation`.
20
20
- Written almost entirely in Swift on top of the Objective-C runtime[^2].
21
21
22
-
## Getting Started
22
+
## Installation
23
23
24
24
- Installation Swift Package Manager
25
25
- Swift 5.9+, Xcode 15+
26
26
- arm64 and x86_64 architectures
27
-
- Examples: instance method on class, class method on class, object
27
+
28
+
## Usage
29
+
30
+
### Class Hook: Instance Method
31
+
32
+
…
33
+
34
+
### Class Hook: Class Method
35
+
36
+
…
37
+
38
+
### Object Hook
39
+
40
+
…
28
41
29
42
## What’s Changed
30
43
@@ -48,14 +61,14 @@ Compared to the [original implementation](https://github.com/steipete/InterposeK
48
61
- Object hooks now use a global counter instead of UUIDs for dynamic subclass names.
49
62
- Dynamic subclasses created at runtime are now cleaned up when the last hook is reverted on an object.
50
63
- Class hooks must now target the exact class that actually implements the method to ensure the revert functionality works correctly.
51
-
- Added initial Swift 6 compatibility with some thread-safety checks. Most usage is still expected to be single-threaded, though.
64
+
- Added initial Swift 6 support with basic concurrency checks. Should be thread-safe, but most usage is still expected to be single-threaded.
52
65
- Removed support for [delayed hooking](https://steipete.com/posts/mac-catalyst-crash-hunt/) (`whenAvailable(…)`) to keep the library laser-focused.
53
66
- …and heavily refactored the Swift part of the codebase: cleaner use of Objective-C runtime APIs, a revamped `InterposeError` enum, and new supporting types like `HookScope` or `HookState`.
54
67
55
68
### Fixes
56
69
57
-
- Fixed a crash where `IKTAddSuperImplementationToClass` was stripped in release builds per [steipete/InterposeKit#29](https://github.com/steipete/InterposeKit#29) by using the fix from [steipete/InterposeKit#30](https://github.com/steipete/InterposeKit#30) submitted by @Thomvis, which replaces a call via dynamic library with a direct Swift call to `IKTSuperBuilder.addSuperInstanceMethod(to:selector:)`.
58
-
- Fixed floating-point register handling on arm64 using the patch from [steipete/InterposeKit#37](https://github.com/steipete/InterposeKit#37) submitted by @ishutinvv, which resolves an issue affecting swizzled methods with `CGFloat` parameters or structs like `CGPoint` and `CGRect` due to floating-point registers not being restored in the correct order after the trampoline call.
70
+
- Fixed a crash where `IKTAddSuperImplementationToClass` was stripped in release builds per [steipete/InterposeKit#29](https://github.com/steipete/InterposeKit/issues/29) by using the fix from [steipete/InterposeKit#30](https://github.com/steipete/InterposeKit/issues/30) submitted by @Thomvis, which replaces a call via dynamic library with a direct Swift call to `IKTSuperBuilder.addSuperInstanceMethod(to:selector:)`.
71
+
- Fixed floating-point register handling on arm64 using the patch from [steipete/InterposeKit#37](https://github.com/steipete/InterposeKit/issues/37) submitted by @ishutinvv, which resolves an issue affecting swizzled methods with `CGFloat` parameters or structs like `CGPoint` and `CGRect` due to floating-point registers not being restored in the correct order after the trampoline call.
0 commit comments