iphone - 将 int 转换为 NSInteger

标签 iphone ios integer nsinteger

<分区>

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

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

最佳答案

改进的答案

在 64 位系统上 NSIntegerlong。在 32 位系统上 NSIntegerinthttps://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/

相关文章:

ios - 旋转 IOS 模拟器 vs 现实

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

将整数转换为 32 位二进制 - 输出向后

iphone - 如何在 iOS 中获取时区列表,就像我们在注册 Web 应用程序时获取的一样

iphone - 从 ruby​​ 运行 shell 脚本

iphone - 将 UTF8 十六进制字符串转换为常规 UTF8 编码的 NSString

将字符串转换为 int(但前提是确实是 int)

class - dart 编程中整数类中的基数是什么?