Skip to Content

iPhone Coding: NSLog on the iPhone

NSLog provides one of the most important debugging tools for your iPhone arsenal. Unlike its Cocoa equivalent, the iPhone NSLog sends information to the command line. It's basically a printf for NS and UI objects. To print an NSString, for example, you might use NSLog(@"String is %@", mystring);. When this line executes, the results print out almost as if you had done a printf("%s", [mystring cStringUsingEncoding:1]); with an extra bit of date and time information attached. Use %@ for objects. Otherwise use the standard C formatting codes: %d for integers, etc.

You will only be able to see NSLog results when your iPhone applications are launched from the command line. Launching them from SpringBoard hides the NSLog information.

The iPhone Crash Reporter provides important information about failed program execution. Go to /Library/Logs/CrashReporter to see dumps from the most recent crash. Dumps are in the form of property list files, which you can open in a text editor or in Apple's Property List Editor.



Categories

iPhone

NSLog provides one of the most important debugging tools for your iPhone arsenal. Unlike its Cocoa equivalent, the iPhone NSLog sends...
 

Add a Comment

*0 / 3000 Character Maximum

7 Comments

Filter by:
Hannes

In what way does this differ from when developing Cocoa apps? The output will go to whatever the stdout pipe is pointed at. If you launch a Cocoa app from command line, like ./Safari.app/Contents/MacOS/Safari it will also display it's output from NSLog and printf and friends, in the terminal window.

August 18 2007 at 5:43 AM Report abuse rate up rate down Reply
R Muffet

Again,

The = article, definite pronoun
Unofficial = no official SDK necessitates hacking, these posts are thus very unofficial
Apple = maker of iPhone, subject of the blog is all things Apple
Weblog = items delivered in easy to read (or dismiss) RSS format

Erica's posts fit the blog's definition admirably.

Posts about Kathy Griffin on the other hand...

August 17 2007 at 9:45 PM Report abuse rate up rate down Reply
Nuno Sousa

You can actually just do: NSLog(str) without providing a format string.

August 17 2007 at 7:11 PM Report abuse rate up rate down Reply
wififun

Erica, Thank you.
To the nay-sayers, skip it. Go read something else. Seriously, just like all the original iPhone coverage, and the crappy posts then. No one is standing over you forcing you to read posts that you have no interest in. Yet, you waste your time, to read it, then more to post a snotty comment. Really, what is the point? Use a RSS reader, there are many to choose from. Skip what you don't care about. This is what is so wonderful about the blogging site format. There may be 100 posts a day at some sites. 5% may interest me. You know what, I just skip right over what I don't care about. Nice and simple. Grow up, or get lost.

As for the relevance of this post. There have been countless arguments as to why these types of posts are relevant here. I feel they are. This is not only relevant, but it was a helpful tip for me and something I was struggling with just last night as I got my toolchain running and successfully compiling my first native iPhone app. So, again thank you for the relevant info.

August 17 2007 at 5:55 PM Report abuse rate up rate down Reply
Fabio P

c'mon quit whining.
me for my part actually think this entry is one of the most useful for this day.
why? well there are different reasons.
on is, this is something you wont read on another blog. most of the other entries are on different blogs about the same. "rumored UI of new iPod", it was on dozens of blogs, all with the very same information.
another part is, thanks to erica i made the efforts to intall SSH on my iphone, so i can use her screenshot tool. i quickly began browsing the filesystem (SSHFS+MacFUSE), making changes to the language files (my iphone is now about 60% german), etc.
without erica having pointed at her screenshot tool, i woudnt even bother loading SSH and therefor never had translated my iphone.
and, i started coding my own app, something really basic, a calculator for some chemistry formulas i often use. its nothing useful, since i have my TI when i need the formulars, but its good to learn the handling of the code.
again, erica showed me that it's actually quite "easy" (easier as i thought at least) to make your own app.

so, all you "own erica you are so boring" (but on a cool thread like vrecorder/screenshot "wow your so greate", you hypocrites), go read another blog.

August 17 2007 at 5:44 PM Report abuse rate up rate down Reply
io_burn

We get it, you're a notorious iPhone h4x0r who is rivaled by none in hacking prowess. I agree with Joseph, please either start a new blog or contain things like this to your personal blog. It's one thing to make iPhone posts for iPhone owners... But making posts targeted at iPhone owners who are developing iPhone applications and are trying to figure out the best way to debug their application.

And even then, why would someone looking for that information come to TUAW?!?

August 17 2007 at 4:49 PM Report abuse rate up rate down Reply
joe

Is there any way you can create a iphone programming blog and take this crap elsewhere? 95% of the readers do not care and couldn't even use this information. I'm sure the irc channels are getting mad anyway at their information leaking out

August 17 2007 at 4:42 PM Report abuse rate up rate down Reply
Buy an ad here

Hot Apps on TUAW

Tweets

© 2012 AOL Inc. All Rights Reserved.