How do I declare a debug only statement

前端 未结 4 1967
说谎
说谎 2021-01-31 02:44

In C# I can use the following code to have code which only executes during debug build, how can I do the same in Xcode?

#if DEBUG
{
    // etc etc
}
#endif
         


        
4条回答
  •  醉梦人生
    2021-01-31 03:38

    You can use

    #ifdef DEBUG
        ....
    #endif
    

    You'll need to add DEBUG=1 to the project's preprocessor symbol definitions in the Debug configuration's settings as that's not done for you automatically by Xcode.

    I personally prefer doing DEBUG=1 over checking for NDEBUG=0, since the latter implies that the default build configuration is with debug information which you then have to explicitly turn off, whereas 'DEBUG=1' implies turning on debug only code.

提交回复
热议问题