Last active
August 29, 2015 14:03
-
-
Save gvkhna/04be1fad32a47aeb07cd to your computer and use it in GitHub Desktop.
objc Method Swap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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