Want more features on Pastebin? Sign Up, it's FREE!
Guest

Method-Swizz-ObjC

By: a guest on Mar 9th, 2012  |  syntax: Objective C  |  size: 0.97 KB  |  views: 113  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #import <objc/runtime.h>
  2. #import <Foundation/Foundation.h>
  3.  
  4. @interface Encryption
  5. - (id) myEncrypt: (NSString *) _secret;
  6. @end
  7.  
  8.  
  9. @implementation Encryption
  10.  
  11. +(void)load
  12. {
  13.         printf("Inside load function\n");
  14.         if (self == [Encryption class]) {
  15.                 printf("inside if\n");
  16.               //  self = [Encryption class];
  17.                 Method origMethod = class_getInstanceMethod(self,@selector(Encrypt:));
  18.                 Method newMethod  = class_getInstanceMethod(self,@selector(myEncrypt:));
  19.                 method_exchangeImplementations(origMethod,newMethod);
  20.         }
  21.         else
  22.         printf("swizzling failed\n");
  23. }
  24.  
  25. - (id) myEncrypt: (NSString *) _secret {
  26.         printf("inside the new encryption\n");
  27.    //     printf("Your Secrect was %s\n", [ _secret UTF8String ]);
  28.         //*_secret = @"HELLO I AM MODIFIED";
  29.    //     printf("The next text sent is %s",[ _secret UTF8String ]);
  30.         return [self myEncrypt:_secret];
  31. }
  32.  
  33. @end
clone this paste RAW Paste Data