iOS筆記:Objective-C自定義NSLog宏

/*
 XCode LLVM XXX - Preprocessing中Debug會添加 DEBUG=1 標誌
 */
#ifdef DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil
#endif

把以上代碼粘貼到ProjectName-Prefix.pch文件中。調試

在調試的時候,會輸出(格式:文件名:行號)日誌。
日誌

在Release正式版本的時候,會關閉日誌輸出。code

相關文章
相關標籤/搜索