01-21-2009, 02:21 PM
#1 (permalink )
Registered Member
Join Date: Nov 2008
Posts: 148
Outputting BOOL in NSLog
What's the % escape for putting a BOOL in NSLog()? I tried %c since BOOL is actually a char but it didn't work.
01-21-2009, 02:23 PM
#2 (permalink )
New Member
Join Date: Aug 2008
Posts: 394
BOOL is an int so %d will work..or you could do
NSLog(@"BOOL = %@\n", (boolVar ? @"YES" : @"NO"));
__________________
Super Pig
iOwn - Inventory anything and everything.
01-21-2009, 02:23 PM
#3 (permalink )
Registered Member
Join Date: Dec 2008
Posts: 495
I think actually BOOL is just a special int, so you should be able to use %i
01-21-2009, 04:23 PM
#4 (permalink )
New Member
Join Date: Sep 2008
Posts: 1,431
If you want to use %i or %d you should cast it to int just in case the char and int are handled differently with varargs. But detz's solution is the way I always do it.
Code:
NSLog(@"BOOL = %d", (int)aBool);
01-24-2009, 05:32 PM
#5 (permalink )
Registered Member
Join Date: Nov 2008
Posts: 148
Thanks
Last edited by john855; 01-24-2009 at 05:41 PM .
01-21-2011, 10:46 PM
#6 (permalink )
Registered Member
Join Date: Aug 2008
Posts: 27
BOOL is, I believe, an NSNumber, not an int.
01-21-2011, 11:01 PM
#7 (permalink )
Reading the Documentation
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
NSNumber is on object class so BOOL is most definitely not an NSNumber. What it is is this:
Quote:
typedef signed char BOOL;
// BOOL is explicitly signed so @encode(BOOL) == "c" rather than "C"
// even if -funsigned-char is used.
#define OBJC_BOOL_DEFINED
#define YES (BOOL)1
#define NO (BOOL)0
But most importantly, this thread is 2 years old.
01-22-2011, 12:39 AM
#8 (permalink )
Registered Member
Join Date: Aug 2008
Posts: 27
You are correct... I read that too. However, when using a BOOL in the context of, for example, core data, one is directed to use an NSNumber rather than an int.
But are you sure that the MOST important point is the age of this thread?
Quote:
Originally Posted by
baja_yu
NSNumber is on object class so BOOL is most definitely not an NSNumber. What it is is this:
But most importantly, this thread is 2 years old.
12-09-2011, 09:46 AM
#9 (permalink )
Registered Member
Join Date: Sep 2009
Posts: 23
Quote:
Originally Posted by
john855
What's the % escape for putting a BOOL in NSLog()? I tried %c since BOOL is actually a char but it didn't work.
Old post but anyways, i usually use this
Code:
NSLog (@"Value of my BOOL = %@", someBool ? @"YES" : @"NO");
Last edited by mrburns05; 12-09-2011 at 09:49 AM .
02-07-2012, 11:41 PM
#10 (permalink )
Registered Member
Join Date: Feb 2012
Posts: 1
Thanks!
Quote:
Originally Posted by
mrburns05
Old post but anyways, i usually use this
Code:
NSLog (@"Value of my BOOL = %@", someBool ? @"YES" : @"NO");
Thanks for this post this did it for me!
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 387
10 members and 377 guests
7twenty7 , Atatator , buggen , guusleijsten , j.b.rajesh@gmail.com , QuantumDoja , sacha1996 , Sami Gh , tim0504 , VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator