I'm working through some exercises and have got a warning that states:
implicit conversion loses integer precision 'NSUInteger' (aka 'unsigned long') to 'int'
I'm quite the noob and would appreciate any help.. thanks.
int main (int argc, const char * argv)
myColors = @[@"Red", @"Green", @"Blue", @"Yellow"];
count = myColors.count; // <<< issue warning here
for (i = 0; i < count; i++)
NSLog (@"Element %i = %@", i, [myColors objectAtIndex: i]);
count method of
NSArray returns an
NSUInteger, and on the 64-bit OS X platform
NSUIntegeris defined as
unsigned long, and
unsigned longis a 64-bit unsigned integer.
intis a 32-bit integer.
int is a "smaller" datatype than
NSUInteger, therefore the compiler warning.
See also NSUInteger in the "Foundation Data Types Reference":
When building 32-bit applications, NSUInteger is a 32-bit unsigned integer. A 64-bit application treats NSUInteger as a 64-bit unsigned integer.
To fix that compiler warning, you can either declare the local
count variable as
or (if you are sure that your array will never contain more than
add an explicit cast:
int count = (int)[myColors count];