banditKing
banditKing

Reputation: 9579

How to output bool value to console in Objective C iPhone

For an object it is

NSLog(@"some object %@", someObject);  

For decimal it is:

NSLog(@"some object %d", 2.33);  

What is it for a bool?

Upvotes: 3

Views: 4171

Answers (1)

Sid
Sid

Reputation: 9536

Treat it like an int:

NSlog(@"%d",yourBool)

... outputs 1 for YES and 0 for NO

If you want to get a YES/NO output use:

NSLog(@"%@", (yourBool ? @"YES" : @"NO"));

The reason, copy-pasted from objc.h:

#define YES             (BOOL)1
#define NO              (BOOL)0




PS: For decimals (floats) it's not %d.... its:

NSLog(@"%f",2.33);

Upvotes: 7

Related Questions