Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSLog giving me warnings which are not correctable

I have the following line of code in my Mac OS X application:

NSLog(@"number of items: %ld", [urlArray count]);

And I get the warning: "Format specifies type 'long' but the argument has type 'NSUInteger' (aka 'unsigned int')"

However, if I change my code to:

NSLog(@"number of items: %u", [urlArray count]);

I get the warning:

Format specifies type 'unsigned int' but the argument has type 'NSUInteger' (aka 'unsigned long')

So then I change it to

NSLog(@"number of items: %u", [urlArray count]);

but I get the warning: Format specifies type 'unsigned long' but the argument has type 'NSUInteger' (aka 'unsigned int')

How can I set up my NSLog so it does not generate a warning? If I follow Xcode's suggestions i just get into in an endless loop of changing the format specifier but the warnings never go away.

like image 823
Jackson Avatar asked Nov 13 '12 06:11

Jackson


3 Answers

Yeah this is annoying. It is a 32/64 bit thing I believe. The easiest thing to do is just cast to a long:

NSLog(@"number of items: %lu", (unsigned long)[urlArray count]);
like image 161
D.C. Avatar answered Oct 16 '22 17:10

D.C.


The portability guide for universal applications suggest casting in this case.

NSLog(@"number of items: %ld", (unsigned long)[urlArray count]);
like image 37
jarjar Avatar answered Oct 16 '22 19:10

jarjar


Another option is mentioned here: NSInteger and NSUInteger in a mixed 64bit / 32bit environment

NSLog(@"Number is %@", @(number));
like image 27
geowar Avatar answered Oct 16 '22 19:10

geowar