在入手新的项目时很多类和项目文件层次都不清楚,最快熟悉项目的方法个人认为是挂断点分析代码。但是如果是企业级项目或者模块代码量很大。不知道怎么入手或者想修复一个bug又不知道调用的哪个ViewController这种情况的话可以用runtime 给每个ViewController添加分类的功能打印调用的是哪个ViewController!
#import "UIViewController+Swizzling.h"#import@implementation UIViewController (Swizzling)
+ (void)load {
#ifdef DEBUG
Method vieWillAppear = class_getInstanceMethod(self, @selector(viewWillAppear:));
Method logViewWillAppear = class_getInstanceMethod(self, @selector(logViewWillAppear:));
method_exchangeImplementations(vieWillAppear, logViewWillAppear);
#endif
}
- (void)logViewWillAppear:(BOOL)animation {
NSString *className = NSStringFromClass([self class]);
NSLog(@"%@ will appear",className);
[self logViewWillAppear:animation];
}