Objective C中`int`数组的长度 [英] Length of an `int` array in Objective C
问题描述
我正在将一个整数数组传递给一个函数.接下来我想遍历数组.在 C 和 C++ 中,这通过简单地使用 arrayname.length
来工作,它给出了数组中的元素数量.在 Objective-C 中找到它的方法是什么?
I am passing an Integer array to a function.
Next I want to traverse through the array.
In C and C++ this worked by simply using arrayname.length
which gave the number of elements in array. What is the way to find that in Objective-C?
[NSArrayObject length]
适用于 NSArray
类型,但我希望它适用于 int[]
.甚至 [XYZ count]
都不起作用(已经建议的答案),所以我在这里寻找另一种方法.
[NSArrayObject length]
works for NSArray
type but I want it for int[]
. Not even [XYZ count]
works (an already suggested answer) so I'm looking for another way here.
推荐答案
没有任何特定于 Objective-C 的整数数组.您将使用与使用 C 相同的技术.
There isn't anything specific to Objective-C with an array of ints. You would use the same technique as if you were using C.
sz = (sizeof foo) / (sizeof foo[0]);
这篇关于Objective C中`int`数组的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!