将int转换为NSInteger [英] Converting int to NSInteger

查看:186
本文介绍了将int转换为NSInteger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何将NSInteger转换为int?

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

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.

推荐答案

改进的答案



在64位系统上 NSInteger long 。在32位系统上 NSInteger int
https://developer.apple .com / library / content / documentation / Cocoa / Conceptual / Cocoa64BitGuide / 64BitChangesCocoa / 64BitChangesCocoa.html

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

您只需要投出 int to NSInteger

All you need just cast your int to NSInteger.

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

您还可以将 NSInteger 投射到 int (如原始答案中所述),但您必须小心64位系统,因为 NSInteger 可能超过 int 限制。

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.

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

没有大科学。 :)

这篇关于将int转换为NSInteger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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