到一個(gè)新公司,最艱難的時(shí)刻就是前一周,項(xiàng)目代碼不熟悉,人也都不認(rèn)識(shí),關(guān)鍵項(xiàng)目文檔還> 缺失,尼瑪,真是各種不爽
剛?cè)胄鹿緯r(shí),一般不可能對(duì)項(xiàng)目結(jié)構(gòu)快速掌握,假如任務(wù)是類(lèi)似修改頁(yè)面的bug,就找頁(yè)面對(duì)應(yīng)文件可能就很費(fèi)事,多個(gè)頁(yè)面的話(huà)簡(jiǎn)直能讓人找的上火。如果能迅速定位當(dāng)前頁(yè)面及相關(guān)跳轉(zhuǎn)頁(yè)面文件位置,那么問(wèn)題就能變得簡(jiǎn)單些。
-
使用category動(dòng)態(tài)添加的方法,release時(shí)自動(dòng)關(guān)閉打印位置,對(duì)工程無(wú)影響
-
一鍵導(dǎo)入,只需導(dǎo)入頭文件"UIViewController+SWIZZLocaltion.h",簡(jiǎn)單方便
-
盡可能詳細(xì)的描述跳轉(zhuǎn)信息,有更詳盡的描述方案敬請(qǐng)留言
核心代碼片段
#ifdef DEBUG
+ (void)load{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Method orginWillAppear = class_getInstanceMethod([self class], @selector(viewWillAppear:));
Method swizWillAppear = class_getInstanceMethod([self class], @selector(location_viewWillAppear:));
bool isAddWillAppear = class_addMethod([self class], @selector(viewWillAppear:), method_getImplementation(swizWillAppear), method_getTypeEncoding(swizWillAppear));
if (isAddWillAppear) {
class_replaceMethod([self class], @selector(location_viewWillAppear:), method_getImplementation(orginWillAppear), method_getTypeEncoding(orginWillAppear));
} else {
method_exchangeImplementations(orginWillAppear, swizWillAppear);
}
});
}
#endif
#pragma mark - SwizzMethods
- (void)printViewLocaltiionAndJumpRelation{
if (![self isKindOfClass:[UITabBarController class]]&&![self isKindOfClass:[UINavigationController class]]) {
NSString *logStr;
if ([[self parentViewController] isKindOfClass:[UINavigationController class]]) {
logStr = @"push跳轉(zhuǎn)";
if (self.presentingViewController) {
logStr = @"present+Navi跳轉(zhuǎn)";
}
for (UIViewController *viewControl in self.navigationController.viewControllers) {
logStr = [logStr stringByAppendingFormat:@"-->%@",[viewControl.class description]];
}
}else if(self.presentingViewController){//presentingViewController 上一視圖
logStr = @"present跳轉(zhuǎn)-->";
if ([self.presentingViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navi = (UINavigationController *)self.presentingViewController;
logStr = [logStr stringByAppendingFormat:@"%@-->%@",[[navi.viewControllers lastObject].class description],[self.class description]];
}else{
logStr = [logStr stringByAppendingFormat:@"%@-->%@",[self.presentingViewController.class description],[self.class description]];
}
}else{
logStr = [NSString stringWithFormat:@"未知跳轉(zhuǎn)-->%@",[self.class description]];
}
NSLog(@"強(qiáng)大的黑魔法 %@",logStr);
}
}
最后附上小demo:ViewControllerLocaltion