Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.
BOOL myBool;
myBool = YES;
if (myBool) {

I have read that because there are instances where the above does not actually call the doFoo() function, it is best to instead always test against YES, as such:

if (myBool == YES)

But for the most part this just makes my code wordy and repetitive. Any thoughts?

share|improve this question

1 Answer 1

I think this StackOverflow thread will be of help to you:


As a quick summary, using the BOOL typedef is dangerous because comparing a value to YES is more restrictive then comparing it to any truthy value. If your above code is not actually evaluating to true, then it must be evaluating to FALSE/NO.

share|improve this answer
BOOL uses a signed char as the backing store. So among other reasons, casts and truncation can occur at unexpected times if you aren't careful and aware of how it works. From the link @keaton_fu provided, @Meltemi links to a good article that describes the sharp corners of BOOL in more depth than any of the answers here if you want more background. –  JustinC Jun 25 '13 at 12:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.