Skip to content

Instantly share code, notes, and snippets.

@elfenlaid
Last active December 14, 2015 13:28
Show Gist options
  • Save elfenlaid/5094024 to your computer and use it in GitHub Desktop.
Save elfenlaid/5094024 to your computer and use it in GitHub Desktop.
// 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