SHARE
TWEET

Method-Swizz-ObjC

a guest Mar 9th, 2012 171 Never
  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
RAW Paste Data
Top