在Cocoa你喜欢NSInteger还是int,为什么? [英] In Cocoa do you prefer NSInteger or int, and why?

查看:161
本文介绍了在Cocoa你喜欢NSInteger还是int,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSInteger / NSUInteger 是Cocoa定义的常规内置类型的替换。

NSInteger/NSUInteger are Cocoa-defined replacements for the regular built-in types.

使用NS *类型对内置函数有什么好处吗?你喜欢什么和为什么?在32位/ 64位平台上 NSInteger int 相同的宽度吗?

Is there any benefit to using the NS* types over the built-ins? Which do you prefer and why? Are NSInteger and int the same width on 32-bit / 64-bit platforms?

推荐答案

我理解的方式是NSInteger et al。是相应的C类型的架构安全版本。基本上它们的大小取决于架构,但是例如,NSInteger,保证有当前架构的任何有效的指针。

The way I understand it is that NSInteger et al. are architecture safe versions of the corresponding C types. Basically their size vary depending on the architecture, but NSInteger, for example, is guaranteed to hold any valid pointer for the current architecture.

Apple建议您使用这些工作与OS X 10.5及以后,和苹果的API:s将使用它们,所以它绝对是一个好主意,以习惯使用它们。他们需要更多的打字,但除此之外,似乎没有任何理由不使用它们。

Apple recommends that you use these to work with OS X 10.5 and onwards, and Apple's API:s will use them, so it's definitely a good idea to get into the habit of using them. They require a little more typing, but apart from that it doesn't seem to be any reason not to use them.

这篇关于在Cocoa你喜欢NSInteger还是int,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆