第一次这么大规模的使用runtime , 原来只知道runtime, 但是感觉离我的生活好远, 偶尔使用还是改输入框的光标的颜色 😂😂. 这次时间紧, 任务重, 为了节省时间, 就打上了runtime的主意
没想到这么好用
果然人都是被逼出来的
#import "UIViewController+LoadVC.h"
#import <objc/runtime.h>
@implementation UIViewController (LoadVC)
+(void)load{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Method oldMethod = class_getInstanceMethod([self class], @selector(viewWillAppear:));
Method newMethod = class_getInstanceMethod([self class], @selector(hook_ViewWillAppear:));
method_exchangeImplementations(oldMethod, newMethod);
});
}
-(void)hook_ViewWillAppear:(BOOL)appear{
NSString *className = NSStringFromClass([self class]);
NSLog(@"%@ will appear", className);
[self hook_ViewWillAppear:appear];
}
@end