Jrswizzle
one-stop-shop for all your method swizzling needs
Install / Use
/learn @rentzsch/JrswizzleREADME
JRSwizzle
Description
JRSwizzle is source code package that offers a single, easy, correct+consistent interface for exchanging Objective-C method implementations ("method swizzling") across many versions of Mac OS X, iOS, Objective-C and runtime architectures.
More succinctly: JRSwizzle wants to be your one-stop-shop for all your method swizzling needs.
Download
$ cd /path/to/top/of/your/project
$ git submodule add git://github.com/rentzsch/jrswizzle.git JRSwizzle semver-1.x
$ git submodule init && git submodule update
# OPTIONAL: Execute the following commands if you want to explicitly peg
# to a certain version. Otherwise `git submodule update` will keep you
# current with HEAD.
$ cd JRSwizzle
$ git checkout v1.1.0
Reasons for Existence
- Easy: Just do this:
[SomeClass jr_swizzle:@selector(foo) withMethod:@selector(my_foo) error:&error];Voila. - Correct: There's a subtle interaction between method swizzling and method inheritance. Following in Kevin Ballard's footsteps, this package Does The Right Thing.
- Compatible: JRSwizzle should Just Work on any version of Mac OS X and iOS you care about. Here's the exhaustive compatibility list:
- Mac OS X v10.3/ppc (Ballard implementation)
- Mac OS X v10.4/ppc (Ballard implementation)
- Mac OS X v10.4/i386 (Ballard implementation)
- Mac OS X v10.5/ppc (method_exchangeImplementations+Ballard implementation)
- Mac OS X v10.5/i386 (method_exchangeImplementations+Ballard implementation)
- Mac OS X v10.5/ppc64 (method_exchangeImplementations+Ballard implementation)
- Mac OS X v10.5/x86_64 (method_exchangeImplementations+Ballard implementation)
- iOS 2.0+ (method_exchangeImplementations+Ballard implementation)
- Robust: All parameters are checked and JRSwizzle returns an optional
NSErrorwith high-quality diagnostics.
Support
Please use JRSwizzle's GitHub Issues tab to file bugs or feature requests.
To contribute, please fork this project, make+commit your changes and then send me a pull request.
Comparison
There's at least four swizzling implementations floating around. Here's a comparison chart to help you make sense of how they relate to each other and why JRSwizzle exists.
<table> <tr> <th>Scenario</th> <th>Swizzle Technology</th> <th>Method Implementation</th> <th>Correct Behavior</th> <th>10.4</th> <th>64-bit</th> </tr> <tr> <td>1</td> <td>Classic</td> <td>Direct</td> <td>YES</td> <td>YES</td> <td>NO</td> </tr> <tr> <td>2</td> <td>Classic</td> <td>Inherited</td> <td>NO</td> <td>YES</td> <td>NO</td> </tr> <tr> <td>3</td> <td>Ballard</td> <td>Direct</td> <td>YES</td> <td>YES</td> <td>NO</td> </tr> <tr> <td>4</td> <td>Ballard</td> <td>Inherited</td> <td>YES</td> <td>YES</td> <td>NO</td> </tr> <tr> <td>5</td> <td>Apple</td> <td>Direct</td> <td>YES</td> <td>NO</td> <td>YES</td> </tr> <tr> <td>6</td> <td>Apple</td> <td>Inherited</td> <td>NO</td> <td>NO</td> <td>YES</td> </tr> <tr> <td>7</td> <td>JRSwizzle</td> <td>Direct</td> <td>YES</td> <td>YES</td> <td>YES</td> </tr> <tr> <td>8</td> <td>JRSwizzle</td> <td>Inherited</td> <td>YES</td> <td>YES</td> <td>YES</td> </tr> </table>- Classic is the canonical
MethodSwizzle()implementation as described in CocoaDev's MethodSwizzling page. - Ballard is Kevin Ballard's improved implementation which solves the inherited method problem.
- Apple is 10.5's new
method_exchangeImplementationsAPI. - JRSwizzle is this package.
License
The source code is distributed under the nonviral MIT License. It's the simplest most permissive license available.
Version History
-
v1.1.0: Nov 28 2016
- [NEW] Block-based swizzle api. Note it uses
NSInvocationwhich is known to be not the fastest of APIs. (dhcdht)
- [NEW] Block-based swizzle api. Note it uses
-
v1.0: Mar 2 2012
-
[NEW] iOS Support. (Anton Serebryakov)
-
[NEW] Class method swizzling. (outis)
-
-
v1.0d1: May 31 2009
-
[FIX] Soothe valgrind by nulling out
hoisted_method_list->obsolete, which it apparently reads. (Daniel Jalkut) -
[FIX] Xcode 3.2 apparently now needs
ARCHSset explicitly for 10.3 targets. (rentzsch)
-
-
v1.0d0: Apr 09 2009
- Moved to github.
-
v1.0d0: Dec 28 2007
- Under development.
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
