iOS开发-NSLog不打印设置 Prefix

首先在-Prefix.pch,文件里添加以下代码
  1. #ifdef DEBUG
  2. #define NSLog(...) NSLog(__VA_ARGS__)
  3. #define debugMethod() NSLog(@"%s", __func__)
  4. #else
  5. #define NSLog(...)
  6. #define debugMethod()
  7. #endif

    上段代码的意思就是 用宏指令作一个判断,若是DEBUG为真,则编译#ifdef到#endif宏定义,不然编译器就不编译;



    这个DEBUG在哪设置呢,


    在 "Target > Build Settings > Preprocessor Macros > Debug" 里有一个"DEBUG=1"。(默认好像就是)app

  8. 设置为Debug模式下,Product-->Scheme-->SchemeEdit Scheme (1)设置Build Configuration成Debug时,就能够打印nslog了。 (2)设置Release,发布app版本的时候就不会打印了,提升了性能