Created
August 8, 2013 17:09
-
-
Save cruinh/6186568 to your computer and use it in GitHub Desktop.
example of using apple's method_exchangeImplementations from objective-c runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)atest1 | |
{ | |
NSLog(@"this is test 1"); | |
} | |
- (void)atest2 | |
{ | |
NSLog(@"this is test 2"); | |
[self atest2]; | |
} | |
- (void)testExchange | |
{ | |
Method originalMethod = class_getInstanceMethod([self class], @selector(atest1)); | |
Method categoryMethod = class_getInstanceMethod([self class], @selector(atest2)); | |
method_exchangeImplementations(originalMethod, categoryMethod); | |
[self atest1]; | |
NSLog(@"The log should show \"this is test 2\" and then \"this is test 1\""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment