Last active
December 14, 2015 13:28
-
-
Save elfenlaid/5094024 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
// Here a cave in which live all runtime dragons and wizards | |
#include <objc/runtime.h> | |
// We can swap instance methods, they start with '-' minus sign, you know | |
static void instance_methods_swap(id object, SEL firstSel, SEL secondSel) { | |
method_exchangeImplementations( | |
class_getInstanceMethod(object, firstSel), | |
class_getInstanceMethod(object, secondSel)); | |
} | |
// Also we can swap class methods, with '+' at start of definition | |
static void class_methods_swap(Class c, SEL firstSel, SEL secondSel) { | |
method_exchangeImplementations( | |
class_getClassMethod(c, firstSel), | |
class_getClassMethod(c, secondSel)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment