将 int 转换为 NSInteger

发布于 2024-12-17 13:22:17 字数 287 浏览 3 评论 0原文

可能的重复:
如何将 NSInteger 转换为 int?

我是新手对于iOS编程,如何将int转换为NSInteger。我找到了有关如何将 NSInteger 转换为 NSNumber 的参考资料,但我无法弄清楚。任何帮助将不胜感激。谢谢。

Possible Duplicate:
How to convert An NSInteger to an int?

I am new to iOS programming, how do I convert int to NSInteger. I have found references on how to convert NSInteger to NSNumber but I wasn't able to figure it out. Any help would be appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好倦 2024-12-24 13:22:17

改进的答案

在 64 位系统上 NSIntegerlong。在 32 位系统上,NSIntegerint
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Cocoa64BitGuide/64BitChangesCocoa/64BitChangesCocoa.html

您只需转换您的 intNSInteger

int i = 1;
NSInteger nsi = (NSInteger) i;

您还可以将 NSInteger 转换为 int (如原始答案中所示),但在 64 位系统上必须小心,因为您的 NSInteger可以超出 int 限制。

原始答案

int i;
NSInteger nsi = 1;
i = nsi;

没什么大科学。 :)

An improved answer

On 64-bit systems NSInteger is long. On 32-bit systems NSInteger is int.
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Cocoa64BitGuide/64BitChangesCocoa/64BitChangesCocoa.html

All you need just cast your int to NSInteger.

int i = 1;
NSInteger nsi = (NSInteger) i;

You can also cast NSInteger to int (as in an original answer), but you must be careful on 64-bit system, because your NSInteger can exceed int limits.

An original answer

int i;
NSInteger nsi = 1;
i = nsi;

No big science. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文