OC
新建->other->PCH file->Build settings->Prefix Header->設(shè)置路徑
- 方法1:打開Finder將pch文件拖進這個路徑->保留MyApp/PrefixHeader.pch
- 方法2:$(SRCROOT)/MyApp/PrefixHeader.pch
在PCH文件中
#ifdef DEBUG
#define DyLog(...) NSLog(__VA_ARGS__)
#else
#define DyLog(...)
#endif
Swift
/*
自定義LOG的目的:
在開發(fā)階段自動顯示LOG
在發(fā)布階段自動屏蔽LOG
print(#file) // 打印所在的方法
print(#function) // 打印所在的行
print(#line) // 打印所在文件的路徑
方法名稱[行數(shù)]: 輸出內(nèi)容
需要在weibo->targets->build setting->搜索custom flag ->在debug加上-D DEBUG
*/
func DyLog<T>(message:T,file:String = #file,function:String = #function,line:Int = #line)
{
#if DEBUG
print("\((file as NSString).lastPathComponent) \(function)[\(line)]:\(message)")
#endif
}