初学Swift发现没有宏定义,只有自己制作NSLog了
定义NSLog是希望只在调试的时候输出所以要先设置相应的环境:
debug环境和release环境切换 点击项目 -Edit Scheme- Run - info - Build Configuration-Debug/Release
自定义NSLog
1、设置DEBUG
2、 在app delegate文件中添加如下代码,添加后则所有控制器都可以使用 #file:获取所在文件的路径 #function:获取所在的方法 #line:获取所在的行数 func LMXLog<T>(message : T , file : String = #file , function : String = #function , line : Int = #line ) { // 获取打印所在的文件 #if DEBUG let fileName = (file as NSString ). lastPathComponent print ( "( \ ( fileName )):( \ ( function )):( \ ( line ))- \ ( message )" ) #endif }