如何向Xcode添加#ifdef DEBUG ?

时间:2021-05-05 15:02:31

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中添加调试设置?我尝试把它放在运行MyApp->参数下的“编辑方案”中,但它不起作用。或者,是否已经有此标志?

2 个解决方案

#1


39  

In recent Xcode project templates there’s already a DEBUG=1 macro defined for the Debug build configuration (in the Preprocessor Macros section). You can test it using the #if preprocessor directive.

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

#2


5  

I usually add my -DDEBUG=1 to 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构建。

#1


39  

In recent Xcode project templates there’s already a DEBUG=1 macro defined for the Debug build configuration (in the Preprocessor Macros section). You can test it using the #if preprocessor directive.

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

#2


5  

I usually add my -DDEBUG=1 to 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构建。