Last active
December 15, 2015 10:39
-
-
Save swillits/5247673 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
void MethodSwizzle(Class c, SEL orig, SEL new) | |
{ | |
Method origMethod = class_getInstanceMethod(c, orig); | |
Method newMethod = class_getInstanceMethod(c, new); | |
if (class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) { | |
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod)); | |
} else { | |
method_exchangeImplementations(origMethod, newMethod); | |
} | |
} | |
MethodSwizzle(openglcontext, @selector(flushBuffer), @selector(my_flushBuffer)); | |
- (void)my_flushBuffer; | |
{ | |
[self my_flushBuffer]; // calls the *original* flushBuffer method (yes it looks weird) | |
<do whatever you want> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment