Xcode if语句永远无法识别活动编译条件

问题描述

enter image description here

enter image description here

如您所见,在我的Active compilation conditions中,我有2个flags(or whatever it is called) A B
我有2个目标,因此第一个目标具有标志A,第二个目标具有标志B ...
在代码中,我试图根据所选的应用程序目标来定义一个值,但是问题是它永远不会进入#if块,而永远不会进入#else块。
我已经尝试解决了几个小时,但没有任何帮助。我还尝试将-D放入我的标志名,并尝试在A中定义BOther Swift Flags ... 什么都没有。

这是我的简单代码:

#if A
    #define kId @"a1a2a3" //never executed.
#else
    #define kId @"b1b2b3" //always executed. Weird thing is also that I put a breakpoint here but its never catched...
#endif

Apple Clang - Preprocessing

解决方法

主动编译条件适用于Swift,类似于Objective-C / C / C ++中的预处理器宏。

在基于C的语言中,以#开头的行是预处理器指令。

由于使用的是Objective-C,因此要在代码中使用#ifA的值应为非零。如果只想测试是否定义了A,则可以改用#ifdef。在A=1下的Preprocessor Macros中定义Apple Clang - Preprocessing

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...