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, Objective-C and runtime architectures.

More succinctly: JRSwizzle wants to be your one-stop-shop for all your method swizzling needs.

Download

JRSwizzle is still under development (set the open tickets) -- when it's ready I'll offer a .zip download link. Until then browse the latest source or check it out with svn co http://rentzsch.com/svn/trunk/cocoa/JRSwizzle.

Reason 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 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)
  • Robust: All parameters are checked and JRSwizzle returns an optional NSError with high-quality diagnostics.

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.

ScenarioSwizzle TechnologyMethod ImplementationCorrect Behavior10.464-bit
1ClassicDirectYESYESNO
2ClassicInheritedNOYESNO
3BallardDirectYESYESNO
4BallardInheritedYESYESNO
5AppleDirectYESNOYES
6AppleInheritedNONOYES
7JRSwizzleDirectYESYESYES
8JRSwizzleInheritedYESYESYES

License

The source code is distributed under the nonviral MIT License. It's the simplest most permissive license available.

Version History

  • v1.0d0: Dec 28 2007: Under development.