0

In Objective-C I can initialize BOOL variable with YES or TRUE. Is there a reason for this?

BOOL test = false;
BOOL test = NO;

Are they the same?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Huang
  • 1,355
  • 2
  • 11
  • 28
  • 2
    See http://stackoverflow.com/questions/615702/is-there-a-difference-between-yes-no-true-false-and-true-false-in-objective-c – Vinzzz Mar 05 '13 at 17:06
  • See http://stackoverflow.com/questions/6420987/why-does-objective-c-use-yes-no-macro-convention-instead-of-true-false – Kaiser Mar 05 '13 at 17:06
  • 2
    @Vinzzz Don't just post a link, vote to close as a duplicate. – rmaddy Mar 05 '13 at 17:08
  • Because everyone has a different favorite, and they didn't want to hurt anyone's feelings. Does it matter? – Hot Licks Mar 05 '13 at 17:09
  • Nothing bad in closing a question. I get hurt when I see downVote. – Anoop Vaidya Mar 05 '13 at 17:13
  • @maddy : I didn't know how to 'vote to close' a question. I see...I had to click that 'flag' and find the good item, ok ! – Vinzzz Mar 05 '13 at 17:31

2 Answers2

3

true and false comes from c / c++

#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0

YES and NO is from Objective-C

#if __has_feature(objc_bool)
#define YES             __objc_yes
#define NO              __objc_no
#else
#define YES             ((BOOL)1)
#define NO              ((BOOL)0)
#endif
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
1

Yes. false is left over from C, NO is more prevalent in idiomatic iOS code and libraries.

David Haynes
  • 933
  • 5
  • 14