开发过程中log的输出对调试起着重要的作用,以下就讲述一下swift开发中的自定义输出。
首先配置一下标识,让Debug模式才打印自定义输出
一般默认创建swift项目 就会有这个DEBUG标识
创建一个swift 文件作为类似OC中的PCH文件
在头文件中编写自定义log输出方法
//自定义输出 #file 指文件名 #line 指所在行数
func QCLog<T>(message : T, file : String = #file, lineNumber : Int = #line) {
//只在debug下输出
#if DEBUG
let fileName = (file as NSString).lastPathComponent
print("[\(fileName):line:\(lineNumber)]- \(message)")
#endif
测试输出效果如下: