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.

Recommended