NSLog Format Specifiers

The quick and simple way to log the value of most datatypes in objective-C.

NSLog(@"%d", somenumber);

The other options are:

%@     Object
%d, %i signed int
%u     unsigned int
%f     float/double
 
%x, %X hexadecimal int
%o     octal int
%zu    size_t
%p     pointer
%e     float/double (in scientific notation)
%g     float/double (as %f or %e, depending on value)
%s     C string (bytes)
%S     C string (unichar)
%.*s   Pascal string (requires two arguments, pass pstr[0] as the first, pstr+1 as the second)
%c     character
%C     unichar
 
%lld   long long
%llu   unsigned long long
%Lf    long double

Source from this blog

4 thoughts on “NSLog Format Specifiers

  1. joel: You can create an NSNumber object with a boolean value – and then output the intValue of the NSNumber… that’s how I have done it in the past.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>