首先確定下項(xiàng)目的 Build Settings 是否已經(jīng)設(shè)置過宏定義 DEBUG
點(diǎn)擊 Build Settings ,然后在搜索框里輸入 macros
如果已經(jīng)設(shè)置過,在 Preprocessor Macros 的 Debug 后面會(huì)有 DEBUG=1,如果沒有,就手動(dòng)設(shè)置下
接下來就可以判斷是否為DEBUG模式了
#ifdef DEBUG
// do sth.
#else
// do sth.
#endif
一般Apple已經(jīng)為我們?cè)O(shè)置好了 DEBUG 的宏定義,所以,我們只要讓 NSLog 在 DEBUG 模式下失效就好了耽装,這樣能讓我們的程序運(yùn)行起來更加穩(wěn)定,同時(shí)我們也可以繼續(xù)使用正規(guī)的 NSLog
// put this in prefix.pch
#ifndef DEBUG
#undef NSLog
#define NSLog(args, ...)
#endif
自定義NSLog期揪,輸出所在的文件和行號(hào)
#ifdef DEBUG
#define DLog( s, ... ) NSLog( @"< %@:(%d) > %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define DLog( s, ... )
#endif
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者