Home

Awesome

imp_implementationForwardingToSelector

Version Platform License Badge

imp_implementationForwardingToSelector is a trampoline that forwards an objc message to a different selector.

Installation

imp_implementationForwardingToSelector is available through CocoaPods, to install it simply add the following line to your Podfile:

pod "imp_implementationForwardingToSelector"

How it works

Message forwarding

imp_implementationForwardingToSelector is a custom trampoline (you can read about trampolines here) which can forward any objc message to a new selector.

IMP imp_implementationForwardingToSelector(SEL forwardingSelector, BOOL returnsAStructValue);

Here is an example

IMP forwardingImplementation = imp_implementationForwardingToSelector(@selector(setCenter:), NO);
class_addMethod([UIView class], @selector(thisSetCenterDoesNotExistYet:), forwardingImplementation, typeEncoding);

and suddenly every instance of UIView responds to -[UIView thisSetCenterDoesNotExistYet:] and forwards this message to -[UIView setCenter:]. If you would like some more information about trampolines and maybe a blog post like Writing custom trampolines for beginners and all the pitfalls, hit me up on Twitter.

Limitations

imp_implementationForwardingToSelector is written in raw assembly which is currently only available on i386, armv7, armv7s and arm64.

Author

Oliver Letterer

License

imp_implementationForwardingToSelector is available under the MIT license. See the LICENSE file for more info.