NSLog and printing outputs


Sorry if this is really basic, but I am really confused about how to identify what needs to be printed–the last time I programmed anything was in the 80s with Fortran.

So, in an NSLog line:

%@ seem to output data
%d outputs a value

When I have something like NSUInterger charCount = [x length], what do I put in an NSLog line to output the result?

Also, how do I find these in the documentation–highlighting them in Xcode does not show anything in Quick Help.


%@ and %d are called format directives. Use %@ when you want to print out the value of an object, and %d to print out the value of an integer variable. (%@ actually causes the object’s decription method to be invoked.)

There are other format specifiers, such as %c and %s. Except for %@, NSLog uses the same format specifiers that are used by the printf function.

Open the Terminal Application, and enter man 3 printf on the command line to get help for printf and format specifiers.

Also in Xcode, Option-click on NSLog to bring up the Foundation Functions Reference, follow the link to NSLogv and then to “String Format Specifiers.”


Thank you.