iphoneiosnsintegerint32

is NSInteger a 32bit integer


Am I correct in thinking that declaring a NSInteger in an ios environment means it will only ever be a 32bit value?

I would like to know as I have been told by another programmer not familiar with objective c to use a int32, the only similar thing I can find in objective C is the int32_t, _t standing for 'integer type'.. but working with these types is becoming a real pain I feel like I dont have all the control functionally thats offered from objective c like NSInteger seems to get.

Any help would be greatly appreciated.


Solution

  • Here is how "NSInteger" is defined in "NSObjCRuntime.h" in older SDK's:

    #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
    

    As of September 2013, iPhones now can run with 64-bit chips, which means a NSInteger might be much bigger.

    In my own coding, if I'm doing pure Objective C, I'll stick with NSInteger since that future-proofs my code for down the line. Open source stuff and certain programmers, on the other hand, love to use "uint32_t" or "int32_t" and other explicit types like this, so when I see those, I try to match their style in the code I'm doing that works with it.