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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 03-18-2010, 07:23 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 4
Default NSLog string output question...

More noob questions... been struggling with NSLog to print out some NSStrings

So I have a label and have been fine with setting the Label dynamically but I also wanted to mirror some NSLog output.

Code:
//  This line works fine for setting the label
yearresultslabel1.text = [NSString stringWithFormat:@"%s", "-- Test Label Text"];

// Now I wanted to dump the label out to the log....
		NSLog(@"My Label now =  %s", yearresultslabel1.text);

// The log outputs "My Label now = !%!@%"  <- basically some funny characters instead of the string I want.  Even tried this with a straight NSString I thought was setup correctly.
So what do I need to do to convert the text into something printable?

TIA.
PhoneKoke is offline   Reply With Quote
Old 03-18-2010, 07:43 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

%@, not %s
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 03-18-2010, 07:43 PM   #3 (permalink)
iPhone SDK learner
 
Join Date: Feb 2010
Location: Illinois, USA
Posts: 417
Default

Quote:
Originally Posted by PhoneKoke View Post
More noob questions... been struggling with NSLog to print out some NSStrings

So I have a label and have been fine with setting the Label dynamically but I also wanted to mirror some NSLog output.

Code:
//  This line works fine for setting the label
yearresultslabel1.text = [NSString stringWithFormat:@"%s", "-- Test Label Text"];

// Now I wanted to dump the label out to the log....
		NSLog(@"My Label now =  %s", yearresultslabel1.text);

// The log outputs "My Label now = !%!@%"  <- basically some funny characters instead of the string I want.  Even tried this with a straight NSString I thought was setup correctly.
So what do I need to do to convert the text into something printable?

TIA.
I'm surprised that works for setting the label. change %s to %@.

EDIT: BrianSlick beat me to it
Batman is offline   Reply With Quote
Old 03-18-2010, 07:46 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

It works in the first case because "..." is a C string, so %s is correct. In the second case, it is now dealing with an NSString object, so it needs to be %@.

"..." = C string
@"..." = NSString
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 03-18-2010, 07:49 PM   #5 (permalink)
iPhone SDK learner
 
Join Date: Feb 2010
Location: Illinois, USA
Posts: 417
Default

Quote:
Originally Posted by BrianSlick View Post
It works in the first case because "..." is a C string, so %s is correct. In the second case, it is now dealing with an NSString object, so it needs to be %@.

"..." = C string
@"..." = NSString
Okay, thanks for explaining that.
Batman is offline   Reply With Quote
Old 03-19-2010, 12:42 AM   #6 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 4
Default

Tks for the help and explanation. This Forum and helpful people are what makes it an awesome resource.
PhoneKoke 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: 294
17 members and 277 guests
@sandris, ADY, dacapo, Dani77, djohnson, dre, HemiMG, JasonR, MarkC, mer10, nibeck, prchn4christ, ryandb2, spiderguy84, timle8n1, tomtom100
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

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