利用runtime實(shí)現(xiàn)的一個(gè)小功能累提。進(jìn)入一個(gè)新頁(yè)面改执,迅速找到對(duì)應(yīng)的ViewController体谒。
#import "UIViewController+Swizzling.h"
#import <objc/runtime.h>
@implementation UIViewController (Swizzling)
+(void)load{
#ifdef DEBUG
Method viewWillAppear = class_getInstanceMethod(self, @selector(viewWillAppear:));
Method logViewWillAppear = class_getInstanceMethod(self, @selector(loadViewWillAppear:));
method_exchangeImplementations(viewWillAppear, logViewWillAppear);
#endif
}
- (void)loadViewWillAppear:(BOOL)animated{
[self loadViewWillAppear:animated];
NSString* className = NSStringFromClass([self class]);
NSLog(@"我的名字是:%@",className);
}
@end