目标C中的`int`数组的长度 [英] Length of an `int` array in Objective C
问题描述
我正在将Integer数组传递给函数.接下来,我想遍历数组.在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计数]
都不起作用(一个已经建议的答案),所以我在这里寻找另一种方法.
[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]);
这篇关于目标C中的`int`数组的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!