How to Log to the Console Using NSLog

Dec 22, 2009   //   by Derek van Vliet   //   Development  //  1 Comment

Xcode has a built in console that provides an invaluable debugging tool for iPhone app development. It gives you a way to monitor text output from your app live at runtime. It works both for apps being debugged in the simulator and on a device.

NSLog

Logging statements to the console is just as easy as you would expect it to be in iPhone app development. Just run the NSLog function like so:

NSLog(@"hello world");

Format Specifiers

The NSLog statement also supports string formatting specifiers, so you can also output the values of variables to the console with just one line. Below are some examples:

NSString * str = @"hello world";
NSLog(@"%@", str);
 
int num = 10;
NSLog(@"%i", num);
 
float price = 1.99;
NSLog(@"%f", price);

1 Comment

  • [...] Play a Video With MPMoviePlayerController 21. How to Upgrade Your iPhone Game to OpenFeint 2.4 22. How to Log to the Console Using NSLog 23. How to Suspend Touch Input 24. How to Open the SMS App With a Phone [...]

Leave a comment

Our Games

Latest Tweets