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.
$ 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
[SomeClass jr_swizzle:@selector(foo) withMethod:@selector(my_foo) error:&error];
Voila.NSError
with high-quality diagnostics.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.
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.
Scenario | Swizzle Technology | Method Implementation | Correct Behavior | 10.4 | 64-bit |
---|---|---|---|---|---|
1 | Classic | Direct | YES | YES | NO |
2 | Classic | Inherited | NO | YES | NO |
3 | Ballard | Direct | YES | YES | NO |
4 | Ballard | Inherited | YES | YES | NO |
5 | Apple | Direct | YES | NO | YES |
6 | Apple | Inherited | NO | NO | YES |
7 | JRSwizzle | Direct | YES | YES | YES |
8 | JRSwizzle | Inherited | YES | YES | YES |
MethodSwizzle()
implementation as described in CocoaDev's MethodSwizzling page.method_exchangeImplementations
API.The source code is distributed under the nonviral MIT License. It's the simplest most permissive license available.
v1.1.0: Nov 28 2016
NSInvocation
which is known to be not the fastest of APIs. (dhcdht)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 ARCHS
set explicitly for 10.3 targets. (rentzsch)
v1.0d0: Apr 09 2009
v1.0d0: Dec 28 2007