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
  • 314,917
  • 42
  • 532
  • 579
Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
  • 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,821
  • 3
  • 25
  • 39