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 > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-26-2011, 11:14 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 36
chicagosky is on a distinguished road
Question Null when printing boolean values

Hello

Please see code and output below. Can someone please help me understand :

1. Why I am printing out 'null' instead of the actual boolean values?

2. What format specifier should I use to print out boolean values?

Code:
    for (NSObject *itr in array) {
        NSLog(@"Class name: '%@'", [itr className]);
        NSLog(@"Is member of NSString: %@", [[itr class] isMemberOfClass:[NSString class]]);
        NSLog(@"Is kind of NSString: %@", [[itr class] isKindOfClass:[NSString class]]);
        NSLog(@"Responds to lowercaseString: %@", [[itr class] respondsToSelector:@selector(lowercaseString)]);
     }
Quote:
2011-03-26 11:10:07.453 WhatATool[69348:903] Class name: 'NSCFString'
2011-03-26 11:10:07.453 WhatATool[69348:903] Is member of NSString: (null)
2011-03-26 11:10:07.453 WhatATool[69348:903] Is kind of NSString: (null)
2011-03-26 11:10:07.454 WhatATool[69348:903] Responds to lowercaseString: (null)
chicagosky is offline   Reply With Quote
Old 03-26-2011, 11:25 AM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

The format specifier %@ is only for objects; it causes NSLog to print the description of the object by calling the description method.

A BOOL is not an object, so you should not use that format specifier for BOOLs. Try using %d instead to get 0 or 1.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 03-26-2011, 11:30 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 36
chicagosky is on a distinguished road
Default

Thank You very much for the speedy reply. It helped to understand the format specifier. I also googled around and found this piece of code that works when wanting to print a string translation of the boolean value

Code:
        NSLog(@"Is member of NSString: %@", [itr isMemberOfClass:[NSString class]] ? @"YES" : @"NO");
        NSLog(@"Is kind of NSString: %@", [itr isKindOfClass:[NSString class]] ? @"YES" : @"NO");
        NSLog(@"Responds to lowercaseString: %@", [itr respondsToSelector:@selector(lowercaseString)] ? @"YES" : @"NO");
Case closed!
chicagosky 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: 480
16 members and 464 guests
7twenty7, AlanFloyd, AppsBlogger, David-T, HemiMG, iAppDeveloper, imac74, Jaxen66, lovoyl, Music Man, mutantskin, Paul Slocum, SLIC, solardrift, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,683
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, unicornleo
Powered by vBadvanced CMPS v3.1.0

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