开发者

How to set a boolean in objective-c

开发者 https://www.devze.com 2023-01-26 18:33 出处:网络
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

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消