Skip to content

Instantly share code, notes, and snippets.

@gvkhna
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gvkhna/04be1fad32a47aeb07cd to your computer and use it in GitHub Desktop.
Save gvkhna/04be1fad32a47aeb07cd to your computer and use it in GitHub Desktop.
objc Method Swap
@implementation _IDESwipeAnimationHostView (OverrideRightClick)
+ (void)load
{
// The "+ load" method is called once, very early in the application life-cycle.
// It's called even before the "main" function is called. Beware: there's no
// autorelease pool at this point, so avoid Objective-C calls.
SEL originalSEL = NULL;
SEL swapSEL = NULL;
Method originalMethod = NULL;
Method swapMethod = NULL;
originalSEL = sel_registerName("rightMouseDown:");
swapSEL = sel_registerName("swap_rightMouseDown:");
if (self && originalSEL && swapSEL) {
originalMethod = class_getInstanceMethod(self, originalSEL);
swapMethod = class_getInstanceMethod(self, swapSEL);
if (originalMethod && swapMethod) {
method_exchangeImplementations(originalMethod, swapMethod);
}
}
}
#pragma mark - Method Swizzling
- (void)swap_rightMouseDown:(id)event {
// super call: self is super at runtime
[self swap_rightMouseDown:event];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment