Objective C – Basic Datatypes and NSLog



Have you been frustrated sometimes trying to debug an application and really making it worse, the output of your logs are not as desired. Complete chaos and nonsense.

Some of the concepts here will be familiar in c coding language, as objective c is just an extended c with object oriented approach. Take a quick look at this table that will surely clear things up.

Type Constants NSLog Short Explanation
char "a", "\n" %c
short int %hi, %hx, %ho %hi, %hx, %ho
unsigned short int %hi, %hx, %ho %hi,
%hx (hex notation),
%ho (octa notation)
int 12, -97, 0xFFE0, 0177 %i, %x, %o also %d can be used in objective-c
unsigned int 12u, 100U, 0xFFU %u, %x, %o as above
long int 12L, -200l, 0xfffL %lu, %lx, %lo as above
long long int 0xe5e5e5e5LL, 500LL %lli, %llx, %llo as above
long long unsigned int 0xe5e5e5e5ULL, 120ULL %llu, %llx, %llo as above
float 12.34f, 3.1e-5f %f, %e, %g %f (with 6 decimal place by default),
%e (with scientific notation), %g (personal preference most readable)
double 12.34, 3.1e-5 %f, %e, %g as above
long double 12.34l, 3.1e-5l %Lf, %Le, %Lg as above
id %p

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>