In the header, it is defined like:
#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
typedef unsigned long NSUInteger;
#else
typedef int NSInteger;
typedef unsigned int NSUInteger;
#endif
So does an UInt32 fit without problems into an NSUInteger (an unsigned int)? Where’s the difference between UInt32 and unsigned int?
And I assume that an unsigned long is bigger than an unsigned int?
I suppose the only difference between a
UInt32and anunsigned intis that aUInt32is guaranteed to be 32 bits long, whereas anunsigned inttechnically could be shorter if you were running (say) on a < 32-bit operating system.However, given that the Mac and the iPhone are both at least 32-bit systems, it’s safe to use
unsigned int,UInt32, andNSUIntegerreasonably interchangeably. The only difference here is that aNSUIntegermight be 64 bits long (on the Mac, when compiling for x86_64).As for your question of
unsigned longversusunsigned int,UInt32is typedef’d to anunsigned long, again indicating that it’s safe to use interchangeably. Anunsigned longis guaranteed to be at least as big as anunsigned int.