|
3 | 3 | [](https://github.com/jsteipete/InterposeKit/actions?query=workflow%3ASwiftPM) |
4 | 4 | [](https://github.com/steipete/InterposeKit/actions?query=workflow%3Axcodebuild) |
5 | 5 | [](https://github.com/steipete/InterposeKit/actions?query=workflow%3A%22pod+lib+lint%22) |
6 | | -[](https://codecov.io/gh/steipete/InterposeKit) |
7 | 6 |  |
8 | 7 |  |
| 8 | +<!-- |
| 9 | +[](https://codecov.io/gh/steipete/InterposeKit) --> |
9 | 10 |
|
10 | 11 | Interpose is a modern library to swizzle elegantly in Swift. It is fully written in Swift 5.2+ and works on `@objc dynamic` Swift functions or Objective-C instance methods. API documentation available at [steipete.github.io/InterposeKit](https://steipete.github.io/InterposeKit/) |
11 | 12 |
|
12 | | -Instead of adding new methods and exchanging implementations, this library replaces the implementation directly. |
| 13 | +Instead of [adding new methods and exchanging implementations](https://nshipster.com/method-swizzling/), this library replaces the implementation directly. |
13 | 14 | This avoids some of [the usual problems with swizzling](https://pspdfkit.com/blog/2019/swizzling-in-swift/). |
14 | 15 |
|
15 | 16 | You can call the original implementation and add code before, instead or after a method call. |
16 | 17 | This is similart o the [Aspects library](https://github.com/steipete/Aspects). |
17 | 18 |
|
| 19 | +## Usage |
| 20 | + |
18 | 21 | Let's say you want to amend `sayHi` from `TestClass`: |
19 | 22 |
|
20 | 23 | ```swift |
@@ -75,6 +78,20 @@ try Interpose.whenAvailable(["RTIInput", "SystemSession"]) { |
75 | 78 | } |
76 | 79 | ``` |
77 | 80 |
|
| 81 | +## FAQ |
| 82 | + |
| 83 | +### Why didn't you call it Interpose? "Kit" feels so old-school. |
| 84 | +Naming it Interpose was the plan, but then [SR-898](https://bugs.swift.org/browse/SR-898) came. While having a class with the same name as the module works [in most cases](https://forums.swift.org/t/frameworkname-is-not-a-member-type-of-frameworkname-errors-inside-swiftinterface/28962), [this breaks](https://twitter.com/BalestraPatrick/status/1260928023357878273) when you enable build-for-distribution. There's some [discussion](https://forums.swift.org/t/pitch-fully-qualified-name-syntax/28482/81) to get that fixed, but this will be more towards end of 2020, if even. |
| 85 | + |
| 86 | +### I want to hook into Swift! You made another ObjC swizzle thingy, why? |
| 87 | +UIKit and AppKit won't go away, and the bugs won't go away either. I see this as a rarely-needed instrument to fix system-level issues. There are ways to do some of that in Swift, but that's a separate (and much more difficult!) project. |
| 88 | + |
| 89 | +### Can I ship this? |
| 90 | +Yes, absolutely. The goal for this one prokect is a simple library that doesn't try to be too smart. I did this in [Aspects](https://github.com/steipete/Aspects) and while I loved this to no end, it's problematic and can cause side-effects with other code that tries to be clever. InterposeKit is boring, so you don't have to worry about conditions like "We added New Relic to our app and now [your thing crashes](https://github.com/steipete/Aspects/issues/21)". |
| 91 | + |
| 92 | +### It does not do X |
| 93 | +Pull Requests welcome! You might wanna open a draft before to lay out what you plan, I want to keep the feature-set minimal so it stays simple and no-magic. |
| 94 | + |
78 | 95 | ## Installation |
79 | 96 |
|
80 | 97 | Building InterposeKit requires Xcode 11.4+ or a Swift 5.2+ toolchain with the Swift Package Manager. |
@@ -107,6 +124,10 @@ Make this happen: |
107 | 124 | [](https://github.com/Carthage/Carthage) |
108 | 125 |  |
109 | 126 |
|
| 127 | +## Thanks |
| 128 | + |
| 129 | +Special thanks to [JP Simard](https://github.com/jpsim/Yams) who did such a great job in setting up [Yams](https://github.com/jpsim/Yams) with GitHub Actions - this was extremely helpful to build CI here fast. |
| 130 | + |
110 | 131 | ## License |
111 | 132 |
|
112 | 133 | InterposeKit is MIT Licensed. |
0 commit comments