将 int 转换为 NSInteger
可能的重复:
如何将 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
改进的答案
在 64 位系统上
NSInteger
是long
。在 32 位系统上,NSInteger
是int
。https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Cocoa64BitGuide/64BitChangesCocoa/64BitChangesCocoa.html
您只需转换您的
int
到NSInteger
。您还可以将
NSInteger
转换为int
(如原始答案中所示),但在 64 位系统上必须小心,因为您的NSInteger
可以超出int
限制。原始答案
没什么大科学。 :)
An improved answer
On 64-bit systems
NSInteger
islong
. On 32-bit systemsNSInteger
isint
.https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Cocoa64BitGuide/64BitChangesCocoa/64BitChangesCocoa.html
All you need just cast your
int
toNSInteger
.You can also cast
NSInteger
toint
(as in an original answer), but you must be careful on 64-bit system, because yourNSInteger
can exceedint
limits.An original answer
No big science. :)