Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the shortest way to negate a BOOL in Objective-C?

I remember in Java you could just go

bool yesNo = YES;
!yesNo;

and it would be NO automatically. I've tried this a few times in Objective-C but it doesn't seem to work. Is there a language specific way to do this in Objective-C?

like image 651
Marty Avatar asked Dec 27 '22 23:12

Marty


1 Answers

It works more or less the same way - you just have to remember to assign the result of the negation expression back to the variable, like so:

yesNo = !yesNo;
like image 137
Sherm Pendley Avatar answered Jan 31 '23 14:01

Sherm Pendley