ios 如何将#ifdef DEBUG 添加到 Xcode?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8257305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 15:33:55  来源:igfitidea点击:

How can I add an #ifdef DEBUG to Xcode?

objective-cciosxcodedebugging

提问by nevan king

I have some code in a project which should never be used in the release build, but is useful when testing. I'd like to do something like this:

我在一个项目中有一些代码,它们永远不应该在发布版本中使用,但在测试时很有用。我想做这样的事情:

#ifdef DEBUG
    // Run my debugging only code
#endif

Where do I add the DEBUG setting in Xcode 4? I tried putting it in the "Edit Scheme" under Run MyApp->Arguments Passed On Launch, but it didn't work. Alternatively, is there a flag already available for this?

我在哪里添加 Xcode 4 中的调试设置?我尝试将它放在 Run MyApp->Arguments Passed On Launch 下的“Edit Scheme”中,但没有奏效。或者,是否有可用的标志?

回答by zoul

In recent Xcode project templates there's already a DEBUG=1macro defined for the Debug build configuration (in the Preprocessor Macrossection). You can test it using the #ifpreprocessor directive.

在最近的 Xcode 项目模板中,已经DEBUG=1为调试构建配置定义了一个宏(在预处理器宏部分)。您可以使用#if预处理器指令对其进行测试。

回答by Michael Dautermann

I usually add my -DDEBUG=1to the OTHER_C_FLAGS section in my XCode 4 project's build settings.

我通常将我-DDEBUG=1的添加到 XCode 4 项目构建设置中的 OTHER_C_FLAGS 部分。

And yes, they can even discriminate between Debug / Release / ADHOC / Store builds.

是的,他们甚至可以区分 Debug / Release / ADHOC / Store builds。