I wrote a method tha uses myarray, defined in the same class. When I use count it always returns 0. When I use:
printf("%d", [myarray count]);
compiler says:
Format '%d' expetcs type 'int', but argument 2 has type 'NSUInteger'
why?
I wrote a method tha uses myarray, defined in the same class. When I use count it always returns 0. When I use:
printf("%d", [myarray count]);
compiler says:
Format '%d' expetcs type 'int', but argument 2 has type 'NSUInteger'
why?
You should use
%lu
instead of%d
. The compiler checks your format string against the parameters that you are passing toprintf
, sees that you are passing an unsigned but print it as a signed integer, and issues a warning. The warning indicates that for numbers greater than or equal to 2^31printf
would output a large negative number, when the data type implies a different semantic, namely, a large positive integer.EDITED in response to comments by Josh Caswell and thepepp