Setting a flag in compiler for NSLog not to show

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

    In Xcode, you can define macros for particular build configurations. For example, here I have DEBUG defined for Debug builds, and nothing for release builds.

    DEBUG flag set for Debug Build Config in Xcode

    Then to use this in the code, wrap your NSLog(...) statements in (or however you choose to use the macro, update:darren's method is quite good with this technique):

    #ifdef DEBUG
        NSLog(...);
    #endif
    

    Use the same mechanism for release configuration only logic.

    You can use this ability if you have various number of build configurations, and you can define more than one macro if you want to enable/disable different levels of functionality for different build configurations.

提交回复
热议问题