简体   繁体   中英

How to set a boolean in objective-c

I am trying to set a boolean, but it won't let me set it true. It keeps telling me that YES is redefined. I am using the method #define YES (q1); where q1 is the boolean.

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;

but its a really bad idea to redefine YES. don't.

I think the define you are looking for is:

#define q1 YES

To verify:

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

if (q1)
{
    // Do something funky
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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