When to use NSInteger vs int?

You usually want to use NSInteger when you don't know what kind of processor architecture your code might run on, so you may for some reason want the largest possible int type, which on 32 bit systems is just an int, while on a 64-bit system it's a long.

I'd stick with using NSInteger instead of int/long unless you specifically require them.

NSInteger/NSUInteger are defined as *dynamic typedef*s to one of these types, and they are defined like this:

1 #if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
2 typedef long NSInteger;
3 typedef unsigned long NSUInteger;
4 #else
5 typedef int NSInteger;
6 typedef unsigned int NSUInteger;
7 #endif

当你不知道你的操作系统是什么类型的时候,你通常会想要使用NSInteger,所以或许你想要你的int类型范围尽可能的大,用NSInteger,32位系统NSInteger是一个int,即32位,但当时64位系统时,NSInteger便是64位的。

http://stackoverflow.com/questions/4445173/when-to-use-nsinteger-vs-int

你可能感兴趣的:(Integer)