Skip to content

Instantly share code, notes, and snippets.

@RuiAAPeres
Created November 13, 2013 17:25
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 RuiAAPeres/7452910 to your computer and use it in GitHub Desktop.
Save RuiAAPeres/7452910 to your computer and use it in GitHub Desktop.
void SwizzleClassMethod(Class c, SEL orig, SEL new) {
Method origMethod = class_getClassMethod(c, orig);
Method newMethod = class_getClassMethod(c, new);
c = object_getClass((id)c);
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment