1、问题
NSArray *mArray ;
int len = [mArray count]; warning implicit conversion loses integer precision 'unsigned long' to int
2、解决方法
方法A:
int count = (int)[mArray count];
方法B:
NSUInteger count;
方法C:
Int count=
[NSNumber numberWithLongLong:cmd.length].intValue;
3、原因
The count
method of NSArray
returns an NSUInteger
, and on the 64-bit OS X platform
NSUInteger
is defined asunsigned long
, andunsigned long
is a 64-bit unsigned integer.int
is a 32-bit integer.
So 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.
引用自