Advertisement
priore

Swizzle Method

Aug 1st, 2012
1,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // www.prioregroup.com
  2. #import <objc/runtime.h>
  3.  
  4. void Swizzle(Class c, SEL orig, SEL newClassName)
  5. {
  6.     Method origMethod = class_getInstanceMethod(c, orig);
  7.     Method newMethod = class_getInstanceMethod(c, newClassName);
  8.     if(class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
  9.         class_replaceMethod(c, newClassName, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
  10.     else
  11.         method_exchangeImplementations(origMethod, newMethod);
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement