简体   繁体   English

NSInteger是一个32位整数

[英]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? 我是否认为在ios环境中声明NSInteger意味着它只会是32位值?

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. 我想知道我不熟悉使用int32的另一个程序员告诉我,我在目标C中找到的唯一类似的东西是int32_t,_t代表'整数类型'..但是使用这些类型正在成为一个真正的痛苦我觉得我没有功能上所提供的目标c像NSInteger似乎得到。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Here is how " NSInteger " is defined in " NSObjCRuntime.h " in older SDK's: 以下是旧版SDK中“ NSObjCRuntime.h ”中定义“ NSInteger ”的方法:

#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. 截至2013年9月,iPhone现在可以运行64位芯片,这意味着NSInteger可能会更大。

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. 在我自己的编码中,如果我正在使用纯粹的Objective C,那么我将坚持使用NSInteger因为这样可以解决我的代码问题。 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. 另一方面,开源的东西和某些程序员喜欢使用“ uint32_t ”或“ int32_t ”以及其他类似的显式类型,所以当我看到这些时,我尝试在我正在做的代码中匹配他们的风格用它。

typedef的存在是为了保护你免受基类型的影响,这就是为什么你使用它们而不是原始类型它的被称为可移植性。

Update iOS 11: NSInteger can be 32-bit or 64-bit depending on the application built and the iOS version. 更新iOS 11:NSInteger可以是32位或64位,具体取决于构建的应用程序和iOS版本。

When building 32-bit applications, NSInteger is a 32-bit integer. 构建32位应用程序时,NSInteger是一个32位整数。 A 64-bit application treats NSInteger as a 64-bit integer. 64位应用程序将NSInteger视为64位整数。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM