The iOS framework that grows only as fast as its documentation
Runtime Class Modifications

Functions

void NISwapInstanceMethods (Class cls, SEL originalSel, SEL newSel)
 
void NISwapClassMethods (Class cls, SEL originalSel, SEL newSel)
 

Overview

For modifying class implementations at runtime.

Attention
Please use caution when modifying class implementations at runtime. Apple is prone to rejecting apps for gratuitous use of method swapping. In particular, avoid swapping any NSObject methods such as dealloc, init, and retain/release on UIKit classes.

See example: Runtime Debugging with Method Swizzling

Function Documentation

NISwapInstanceMethods

Swap two class instance method implementations.

void NISwapInstanceMethods;
Discussion

Use this method when you would like to replace an existing method implementation in a class with your own implementation at runtime. In practice this is often used to replace the implementations of UIKit classes where subclassing isn't an adequate solution.

This will only work for methods declared with a -.

After calling this method, any calls to originalSel will actually call newSel and vice versa.

Uses method_exchangeImplementations to accomplish this.

  • [test] Swap two instance methods on a class.
Examples:
ExampleRuntimeDebugging.m.

NISwapClassMethods

Swap two class method implementations.

void NISwapClassMethods;
Discussion

Use this method when you would like to replace an existing method implementation in a class with your own implementation at runtime. In practice this is often used to replace the implementations of UIKit classes where subclassing isn't an adequate solution.

This will only work for methods declared with a +.

After calling this method, any calls to originalSel will actually call newSel and vice versa.

Uses method_exchangeImplementations to accomplish this.

  • [test] Swap two static methods on a class.