5

Possible Duplicate:
Is there a difference between YES/NO,TRUE/FALSE and true/false in objective-c?

I have one question, and it can be answered quickly. I have this code:

.h

UITableView *table;

.m
table.hidden = YES;
table.hidden = TRUE;

Is there any difference between the last two lines of code ? Or is EXACTLY the same YES and TRUE?

Community
  • 1
  • 1
Adri
  • 243
  • 3
  • 12
  • Actually, there is some nuances of `YES` and `true`. Checkout my interesting question: https://stackoverflow.com/q/65517700/5492956 – wzso Dec 31 '20 at 07:14

3 Answers3

6

The TRUE macro is only provided as backwards-compatibility with C code (Objective-C is designed to be a strict super-set of C). They both mean the same thing.

Chris Browne
  • 1,582
  • 3
  • 15
  • 33
1

The original success value for BOOL in Objective C is the YES. TRUE is just a mimic of it for compatibility. You can use both but I highly recommend you to use what was originally designed for the language. This is important in case future updates of the language changed anything in the syntax of the language (which is not likely to happen in this case), using the original syntax will not cause you to fix anything in your old code.

antf
  • 3,162
  • 2
  • 26
  • 33
0

in objective-c YES and TRUE are the same thing.

In addition these can be expressed as 1 and 0 as they are usually stored this way in core data.

[NSNumber numberWithBool:YES];

MobileOverlord
  • 4,580
  • 3
  • 22
  • 30
  • I would recommend picking one and sticking with it, preferably `YES` since it makes it more obvious you're writing Objective-C code and not pure-C code, but it's really a matter of convention. – Chris Browne Feb 06 '12 at 19:31
  • I believe they use `YES` in Objective-C because of the way they phrase their `BOOL` variables as questions to correspond to the method naming convention. like `BOOL isTrue = YES;` – MobileOverlord Feb 06 '12 at 19:34
  • They are stored like that in CD because Core Data stores objects, which BOOL is not, so it uses NSNumber to store BOOLs, and the class method `numberWithBool` and the instance mathed `boolValue` to store get the scalar value. – Abizern Feb 06 '12 at 19:40