
Method-Swizz-ObjC
By: a guest on
Mar 9th, 2012 | syntax:
Objective C | size: 0.97 KB | hits: 85 | expires: Never
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
@interface Encryption
- (id) myEncrypt: (NSString *) _secret;
@end
@implementation Encryption
+(void)load
{
printf("Inside load function\n");
if (self == [Encryption class]) {
printf("inside if\n");
// self = [Encryption class];
Method origMethod = class_getInstanceMethod(self,@selector(Encrypt:));
Method newMethod = class_getInstanceMethod(self,@selector(myEncrypt:));
method_exchangeImplementations(origMethod,newMethod);
}
else
printf("swizzling failed\n");
}
- (id) myEncrypt: (NSString *) _secret {
printf("inside the new encryption\n");
// printf("Your Secrect was %s\n", [ _secret UTF8String ]);
//*_secret = @"HELLO I AM MODIFIED";
// printf("The next text sent is %s",[ _secret UTF8String ]);
return [self myEncrypt:_secret];
}
@end