Setting a flag in compiler for NSLog not to show

后端 未结 7 1586
野趣味
野趣味 2021-01-21 18:55

Is there any particular flag which can be set to not display NSLog output in either debug or release?

Thanks.

7条回答
  •  清酒与你
    2021-01-21 19:19

    One option might be to use a macro as a replacement for NSLog (if its easy for you to change things at this point). I like the prefix header file these guys use:

    http://www.cimgf.com/2010/05/02/my-current-prefix-pch-file/

    Basically their logging function is:

    #ifdef DEBUG
      #define DLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
    #else
      #define DLog(...) do { } while (0)
    #endif
    

    So if you are not in a DEBUG build, the logging macro becomes a no-op.

提交回复
热议问题