How to print Boolean flag in NSLog?

Viewed 204786

Is there a way to print value of Boolean flag in NSLog?

12 Answers

In Swift, you can simply print a boolean value and it will be displayed as true or false.

let flag = true
print(flag) //true
  • Direct print bool to integer
BOOL curBool = FALSE;
NSLog(@"curBool=%d", curBool);

-> curBool=0

  • Convert bool to string
char* boolToStr(bool curBool){
    return curBool ? "True": "False";
}

BOOL curBool = FALSE;
NSLog(@"curBool=%s", boolToStr(curBool));

-> curBool=False

Related