<分区>
Possible Duplicate:
How to convert An NSInteger to an int?
我是 iOS 编程新手,如何将 int 转换为 NSInteger。我找到了有关如何将 NSInteger 转换为 NSNumber 的引用资料,但我无法弄清楚。任何帮助,将不胜感激。谢谢。
<分区>
Possible Duplicate:
How to convert An NSInteger to an int?
我是 iOS 编程新手,如何将 int 转换为 NSInteger。我找到了有关如何将 NSInteger 转换为 NSNumber 的引用资料,但我无法弄清楚。任何帮助,将不胜感激。谢谢。
最佳答案
在 64 位系统上 NSInteger
是 long
。在 32 位系统上 NSInteger
是 int
。
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Cocoa64BitGuide/64BitChangesCocoa/64BitChangesCocoa.html
您只需将 int
转换为 NSInteger
。
int i = 1;
NSInteger nsi = (NSInteger) i;
您也可以将 NSInteger
转换为 int
(如原始答案),但在 64 位系统上必须小心,因为您的 NSInteger
可以超过 int
限制。
int i;
NSInteger nsi = 1;
i = nsi;
没有大科学。 :)
关于iphone - 将 int 转换为 NSInteger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8226447/
相关文章:
iphone - objective-c : How to highlight the first cell in table view when view loads?
iphone - 将文件夹(带内容)从 bundle 复制到文档目录 - iOS
ios - Alamofire 构建失败 : issues in Manager. swift、Request.swift 和 ResponseSerialization.swift
iphone - 如何在 iOS 中获取时区列表,就像我们在注册 Web 应用程序时获取的一样