简体   繁体   English

如何在objective-c中设置布尔值

[英]How to set a boolean in objective-c

I am trying to set a boolean, but it won't let me set it true. 我试图设置一个布尔值,但它不会让我设置为true。 It keeps telling me that YES is redefined. 它一直告诉我, YES被重新定义。 I am using the method #define YES (q1); 我正在使用方法#define YES (q1); where q1 is the boolean. 其中q1是布尔值。

BOOL yourBool = YES;

Why are you doing this? 你为什么做这个?

#define YES (q1);

its a preprocessor macro to replace all occurences of the word YES with (q1) if thats what you actually want to do(you probably don't), then use BOOL yourBool=TRUE; 它是一个预处理器宏来替换所有出现的单词YES和(q1),如果这是你真正想要做的(你可能不这样做),那么使用BOOL yourBool = TRUE;

but its a really bad idea to redefine YES. 但重新定义YES是一个非常糟糕的主意。 don't. 别。

I think the define you are looking for is: 我认为您正在寻找的define是:

#define q1 YES

To verify: 核实:

NSLog(@"Q1 is set to %@", (q1 ? @"YES" : @"NO"));

if (q1)
{
    // Do something funky
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM