How to check True or False in an Objective-C BOOL variable

I have an NSObject that contains several objects, some of which are BOOL variables that are set to either "T" or "F"

I would like to know how to use them in an If statement, which looks like this.

if (myNSObject.firstBOOL == T) { // do some stuff here } 

I can’t do this, and I’m not sure why, I can ask him if its TRUE or YES , but not T. I searched for answers on other sites, but I try my best to find something similar, so I hoped that someone Someone can offer some understanding.

Any help would be greatly appreciated.

+4
source share
1 answer

With BOOL variables and properties, comparisons with YES / NO or TRUE / FALSE not needed. Is BOOL itself a valid boolean expression that can go into if , triple ? : ? : or loop design without additional comparisons.

You can write this:

 // Use a BOOL in an if if (myObj.boolPropertyOne) { // This will execute if boolPropertyOne is set to True } // Use a BOOL in a loop while (!myObj.boolPropertyTwo) { // This will execute while boolPropertyTwo is set to False } // Use a BOOL in a conditional expression int res = myObj.boolPropertyThree ? 18 : 42; 
+7
source

Source: https://habr.com/ru/post/1480616/


All Articles