Setting a flag in compiler for NSLog not to show

后端 未结 7 1590
野趣味
野趣味 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:26

    Adding this b/c none of the answers seem to address warnings you may have (depending on project settings) with some of these approaches.

    This is the only way I could find to suppress NSLog without getting any warnings. Otherwise I get a ton with the settings we use (warn on unused variables).

    #undef NSLog
    
    #define NSLog(fmt, ...) if (0) { printf("%s", [[NSString stringWithFormat:fmt, ##__VA_ARGS__] UTF8String]); }
    

    Then all you need to do is put that in whatever pch file you use for your release builds or wherever you want to suppress the logs.

    Credit to @Hot Licks for the example of how to make the variable "used".

提交回复
热议问题