UIViewController|UIViewController --------添加分类显示哪个controller将要出现

当你接手一个大项目的时候,对整体的业务逻辑不熟悉,整体的架构体系不熟悉,让你修复某个页面的BUG,估计你找这个页面所对应的viewController都要找好久

能否有一种方式可以快速让你上手一个大项目?快速找到某个页面所对应的viewController ?所以如果能够打印出将要加载viewController 就方便找到对应的内容在哪里了

思路:
我们可以给ViewController添加一个分类,废话不多说,直接上代码:
#import "UIViewController+load.h"

@implementation UIViewController (load)
+ (void)load {
#ifdef DEBUG
//原本的viewWillApper方法
Method viewWillAppear = class_getInstanceMethod(self, @selector(viewWillAppear:));
//需要替换成能够输入日志的viewWillAppear
Method logViewWillAppear = class_getInstanceMethod(self, @selector(logViewWillAppear:));
//两方法进行交换
method_exchangeImplementations(viewWillAppear, logViewWillAppear);
#endif
}
- (void)logViewWillAppear:(BOOL)animated {
NSString *className = NSStringFromClass([self class]);
////在这里,你可以进行过滤操作,指定哪些viewController需要打印,哪些不需要打印
//if ([className hasPrefix:@"UI"] == NO) {
//NSLog(@"%@ will appear",className);
//}
NSLog(@"%@ will appear",className);
//下面方法的调用,其实是调用viewWillAppear
[self logViewWillAppear:animated];
}
【UIViewController|UIViewController --------添加分类显示哪个controller将要出现】@end

    推荐阅读