iOS:用于调试版本的可选代码片段 [英] iOS: optional code fragments for debug builds
问题描述
对于我的应用程序,我想有一个调试视图,我只想在调试版本,而不是在
发布版本。我不想改变我的代码。这是为什么我想知道如果我可以
检查一些编译器标志,如果这是一个发布版本,并排除一些代码,我只想要
有调试版本。
for my App I'd like to have a debug view that I want to have only in debug-builds and not in release builds. I don't want to change my code though. Thats why i am wondering if I can check some compiler flag if this is a release build and exclude some code that i only want to have for debug builds.
推荐答案
在您的项目构建设置中,查找预处理器定义部分,您可以在其中仅在调试版本中定义变量,例如 DEBUG = 1
,然后在代码中使用:
In your projects build settings, look for the preprocessor defines section, in there you can define a variable in your debug build only, such as DEBUG=1
, and then use this in your code:
#if DEBUG
NSLog(@"This will only print in debug!");
#endif
只需确保在发布配置中,同样的定义设置为0在您的构建设置中的相同位置
Just make sure in your release configuration, that same define is set to 0 in the same location in your build settings
这篇关于iOS:用于调试版本的可选代码片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!