Last active
August 29, 2015 14:02
-
-
Save isaldin/ad225ee839c69f99da7d to your computer and use it in GitHub Desktop.
[iOS SDK] override methods in runtime (Swizzling)
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
/* | |
Category implementation | |
*/ | |
#import "UIViewController+Swizzle.h" | |
#import <objc/runtime.h> | |
@implementation UIViewController (Swizzle) | |
+ (void)load | |
{ | |
Method original_appear, swizzle_appear, original_disappear, swizzle_disappear; | |
original_appear = class_getInstanceMethod(self, @selector(viewWillAppear:)); | |
swizzle_appear = class_getInstanceMethod(self, @selector(viewWillAppearExtended:)); | |
original_disappear = class_getInstanceMethod(self, @selector(viewWillDisappear:)); | |
swizzle_disappear = class_getInstanceMethod(self, @selector(viewWillDisappearExtended:)); | |
method_exchangeImplementations(original_appear, swizzle_appear); | |
method_exchangeImplementations(original_disappear, swizzle_disappear); | |
} | |
- (void)viewWillAppearExtended:(BOOL)animated | |
{ | |
NSLog(@"\n===\n\nView will appear\n\n===\n"); | |
return [self viewWillAppearExtended:animated]; | |
} | |
- (void)viewWillDisappearExtended:(BOOL)animated | |
{ | |
NSLog(@"\n===\n\nView will disappear\n\n===\n"); | |
return [self viewWillDisappearExtended:animated]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment