NSInteger

发布时间:2019-08-06 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了NSInteger脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

查到c语言中,int和long的字节数是和操作系统指针所占位数相等。
但c语言中说,long的长度永远大于或等于int
objective-c里,苹果官方文档中总是推荐用NSInteger
原来在苹果的api实现中,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

You usually want to use NSInteger when you don't know what kind of PRocessor ArchITecture your code might run on, so you may for some reason want the largest possible int type, which on 32 bit Systems is just an int, while on a 64-bit system it's a long.

脚本宝典总结

以上是脚本宝典为你收集整理的NSInteger全部内容,希望文章能够帮你解决NSInteger所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。