0

I have read that the two are the same, but my code does not work if I use true/false instead of YES/NO. For example if I do

BOOL matchFound=false;
//...
//logic to change value of matchFound to `true` goes here
//...
if(!matchFound) NSLog(@"I did not find a match");

The above does not work properly. But if I change to using YES/NO, it works. Why is that?

rmaddy
  • 307,833
  • 40
  • 508
  • 550
Katedral Pillon
  • 14,984
  • 21
  • 92
  • 196
  • I'm unable to reproduce. But I would agree with Bas that this is a duplicate (though a good question) so that's moot. – Tommy Jan 21 '15 at 17:52

1 Answers1

7

That is because YES/NO are not actually boolean values, but instead they are signed char types. This is a relic from the old C days where there was no boolean type.

The article linked below will explain in more details, but in general you should always use YES/NO when dealing with BOOL values in iOS.

http://iosdevelopertips.com/objective-c/of-bool-and-yes.html

Hope this helps!

miken.mkndev
  • 1,691
  • 3
  • 23
  • 38
  • 4
    ... with the caveat that in the 64-bit runtime `BOOL` is explicitly a typedef for C99's `bool`. – Tommy Jan 21 '15 at 17:55