在项目开发和调试中,我们经常需要知道我们当前所在的控制器,以便进行开发,bug调试,数据监控,问题排查等。我们可以在base里获取当前所在的控制器,详情不解释,看代码!
import UIKit
classBaseViewController:UIViewController{
overridefuncviewWillAppear(_animated:Bool) {
super.viewWillAppear(animated)
UIApplication.shared.statusBarStyle = .default
//获取当前系统时间
letdate=Date()
lettimeFormatter =DateFormatter()
timeFormatter.dateFormat="yyyy-MM-dd HH:mm:ss"
letstrNowTime = timeFormatter.string(from: date)asNSString
//获取当前控制器
varclassName =NSString.self()
className =String(describing:self.classForCoder)asNSString
if!(className.hasPrefix("UI")){
print("log:\(strNowTime) \(className)")
}
}
overridefuncviewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.white
}
overridefuncdidReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
控制台日志:
