常量的条件编译警告

时间:2013-02-15 17:00:23

标签: objective-c xcode cocoa const definition

问题

我想在我的TESTING为YES时触发警告。这可能吗?我现在所做的并不起作用。我该怎么办?

BOOL const TESTING = NO;
#if TESTING == YES
    #warning don't forget to turn testing to NO before upload
#endif

ANSWER

基于以下答案,这对我有用:

#define _TESTING // COMMENT THIS OUT TO DISABLE TESTING MODE
#ifdef _TESTING
    BOOL const TESTING = YES;
    #warning don't forget to turn testing to NO for production
#else
    BOOL const TESTING = NO;
#endif

1 个答案:

答案 0 :(得分:2)

尝试用

替换你拥有的东西
#ifdef TESTING
  #warning //... warning here
  BOOL const testingBool = YES;
#else
  BOOL const testingBool = NO;
#endif

然后,您需要在目标的构建设置中将TESTING添加为“预处理器宏”(有关如何执行此操作的更多详细信息,请参阅this问题。)