NSInteger is a 32-bit integer

Am I right in believing that declaring NSInteger in ios means that it will ever be just a 32-bit value?

I would like to know how another programmer who is not familiar with the c lens told me to use int32, the only thing I can find in the C lens is int32_t, _t, which stands for the "integer type" .. but working with these types becomes real pain. I feel like I don’t have all the functions functionally accessible from objective c, as it seems that NSInteger is receiving.

Any help would be greatly appreciated.

+4
source share
4 answers

This is how " NSInteger " is defined in " NSObjCRuntime.h " in older SDKs:

 #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 can now work with 64-bit chips, which means that NSInteger can be much larger.

In my own coding, if I make pure Objective-C, I will stick with NSInteger , as this future confirms my code for the string. On the other hand, open source materials and some programmers like to use " uint32_t " or " int32_t " and other explicit types like this, so when I see them, I try to match their style in the code I'm working with.

+7
source

According to the C standard, int32_t is a 32-bit wide integer type.

NSInteger is an integral type whose width is defined as the width of a machine word on the target platform, which in practice can be either 32 or 64 bits. IOS always has 32 bits.

Thus, in practice, these two are literally interchangeable until you hear about 64-bit iOS.

+4
source

There are typedef types that protect you from the base type, so you use them instead of raw types called portability.

0
source

IOS 11 update: NSInteger can be 32-bit or 64-bit depending on the embedded application and the version of iOS.

When creating 32-bit applications, NSInteger is a 32-bit integer. A 64-bit application sees NSInteger as a 64-bit integer.

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

0
source

All Articles