Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-21-2009, 02:21 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 148
john855 is on a distinguished road
Default 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.
john855 is offline   Reply With Quote
Old 01-21-2009, 02:23 PM   #2 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 394
detz is on a distinguished road
Default

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.
detz is offline   Reply With Quote
Old 01-21-2009, 02:23 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 495
exorcyze is on a distinguished road
Default

I think actually BOOL is just a special int, so you should be able to use %i
__________________
My Apps on AppStore : gScale (guitar scales reference), eMaze, eMaze Lite, eTimesheet
exorcyze is offline   Reply With Quote
Old 01-21-2009, 04:23 PM   #4 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
PhoneyDeveloper is on a distinguished road
Default

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);
PhoneyDeveloper is offline   Reply With Quote
Old 01-24-2009, 05:32 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 148
john855 is on a distinguished road
Default

Thanks

Last edited by john855; 01-24-2009 at 05:41 PM.
john855 is offline   Reply With Quote
Old 01-21-2011, 10:46 PM   #6 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 27
superuser is on a distinguished road
Send a message via AIM to superuser
Default

BOOL is, I believe, an NSNumber, not an int.
superuser is offline   Reply With Quote
Old 01-21-2011, 11:01 PM   #7 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

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.
baja_yu is offline   Reply With Quote
Old 01-22-2011, 12:39 AM   #8 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 27
superuser is on a distinguished road
Send a message via AIM to superuser
Default

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 View Post
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.
superuser is offline   Reply With Quote
Old 12-09-2011, 09:46 AM   #9 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 23
mrburns05 is on a distinguished road
Smile

Quote:
Originally Posted by john855 View Post
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.
mrburns05 is offline   Reply With Quote
Old 02-07-2012, 11:41 PM   #10 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 1
osaban is on a distinguished road
Default Thanks!

Quote:
Originally Posted by mrburns05 View Post
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!
osaban is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» 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
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:38 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0