24 January 2009

Author

Jan Vantomme

Categories

iPhone
Workflow

Using NSLog to debug your iPhone application

I’ve done a lot of generative design in the last years. First in Macromedia Director and for the last two years I’ve been using Processing. Somewhere last week I started to play with the iPhone SDK and it’s quite easy to create small applications. I’ll probably create a small generative iPhone application in 2009 and write about what I’m learning right here.

Debugging Processing

Logging messages to the console in Processing is really easy. Just use the println(); function like in the example below.

int myNumber = 3;
String myText = "Dog";
println("My number is " + myNumber + " and my text is "
    + myText + ".");

This little snippet of code will log the text “My number is 3 and my text is dog.” to the console.

Debugging Objective-C

If you would convert this snippet code to Objective-C, you will get something like this:

int myNumber = 3;
NSString *myText = @"Dog";
NSLog("My number is %i and my text is %@.", myNumber,
    myText);

The NSLog function replaces %i with myNumber and %@ with myText. %i and %@ are called format specifiers. They tell the NSLog function what type of variable myNumber and myText are. %i is used to represent an integer, %@ is used to represent an object. In this case myText is an NSString object.

Format Specifiers

And to finish this article i’ll give you a short list with the most common format specifiers you’ll need to debug your application.

  • %i, %d signed integer
  • %u unsigned integer
  • %f float
  • %@ object

Top · Tweet about this

Browse Articles

Previous Article:
Next Article:

0 Opinions posted so far. Now go post your own. To the comment form!

Commenting is closed for this article.

Subscribe to this blog

About this blog

This is the personal weblog of Jan Vantomme.
I write about the everyday things that move me as a designer. I write shorter things on Twitter.

Add to Technorati Favorites

Some of the blogs I like

Subtraction
A blog on design by Khoi Vinh
A List Apart
Great articles every webdesigner should read
And All That Malarkey
Transcending CSS and other things
Aral Balkan
Confessions of an internet junkie.
Unit Interactive Blog
The blog of Unit Interactive