NSInteger 到 NSArray iPhone
我有 NSInteger 变量,例如 NSInteger example=1256,我需要一个包含该变量元素的数组。
so first element of array is array[0] = 1
array[1] = 2
array[2] = 5 etc..
我可以用什么方法解决它?
I have NSInteger variable, for example NSInteger example=1256 and i need an array with elements of this variable.
so first element of array is array[0] = 1
array[1] = 2
array[2] = 5 etc..
what way can i solve it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是我的做法:
Here's about how I'd do it:
您需要使用 NSMutableArray 才能更改条目。 NSMutableArray 只能保存对象,不能保存像 NSInteger 这样的基本类型。另外,如果您使用 NSMutableArray,则无法以与 C 数组相同的方式访问元素。
You need to use NSMutableArray to be able to change entries. NSMutableArray can only hold objects, not primitive types like NSInteger. Also, if you are using NSMutableArray, you can't access the elements the same way as with a C array.
您可以将整数转换为 char*,然后迭代它,将每个字符转换回 int 并将其添加到 C 数组中,或者如 Steven 所说,添加到 NSNumbers 的 NSArray 中。
You can convert your integer to a char* then iterate through it casting each character back to an int and adding it to a C array or, as Steven says, an NSArray of NSNumbers.