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.
Share
Categories
NSLog provides one of the most important debugging tools for your iPhone arsenal. Unlike its Cocoa equivalent, the iPhone NSLog sends...
Add a Comment
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 Permalink rate up rate down ReplyAgain,
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...
You can actually just do: NSLog(str) without providing a format string.
August 17 2007 at 7:11 PM Report abuse Permalink rate up rate down ReplyErica, 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.
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.
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?!?
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 Permalink rate up rate down ReplyHot Apps on TUAW
Deals of the Day
more deals- Altec Lansing Octiv Duo iDock for $48 + free shipping
- Used Apple iMac 17" Core 2 Duo 1.83GHz for $430 + $28 s&h
- Lounge Deluxe Stand for iPhone / iPod touch for $28 + $8 s&h
- Brookstone Surround-Sound Earbuds for $14 + $7 s&h
- Refurbished Skullcandy Tokidoki Smokin' Buds Mic'd Headset for $5 + $2 s&h
- Stitchway Backup Battery for iPod / iPhone for $5 + free shipping
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



7 Comments