문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

The typedefs exist to shield you from the base type, thats why you use them instead of the raw types its called portability.

Update iOS 11: NSInteger can be 32-bit or 64-bit depending on the application built and the iOS version.

When building 32-bit applications, NSInteger is a 32-bit integer. A 64-bit application treats NSInteger as a 64-bit integer.

https://developer.apple.com/documentation/objectivec/nsinteger

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top