使用runtime特性新建一个类目,然后创建一个pch 文件,里面写上 #define LogController,将其写入DEBUG宏中,发布正式版本的时候,这些日志就不会打印了,这样就能看到APP启动之后ViewController的启动顺序了
显示界面之后ViewController的启动顺序#import "UIViewController+Debug.h"
#import <objc/objc-runtime.h>
@implementation UIViewController (Debug)
+ (void)load
{
#ifdef LogController
Method viewWillAppear = class_getInstanceMethod(self, @selector(viewWillAppear:));
Method logViewWillAppear = class_getInstanceMethod(self, @selector(logViewWillAppear:));
method_exchangeImplementations(viewWillAppear, logViewWillAppear);
#endif
}
- (void)logViewWillAppear:(BOOL)animated
{
NSString *className = NSStringFromClass([self class]);
if ([className containsString:@"Controller"]) {
NSLog(@"----- %@ ----- is appearing",className);
}
[self logViewWillAppear:animated];
}
@end
网友评论