利用runtime实现的一个小功能。进入一个新页面,迅速找到对应的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