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.
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]);
The portability guide for universal applications suggest casting in this case.
NSLog(@"number of items: %ld", (unsigned long)[urlArray count]);
Another option is mentioned here: NSInteger and NSUInteger in a mixed 64bit / 32bit environment
NSLog(@"Number is %@", @(number));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With