简体   繁体   English

循环遍历NSArray objectAtIndex

[英]Loop through NSArray objectAtIndex

NSInteger *count = [monLessonArrayA count]; NSInteger * count = [monLessonArrayA count]; for (i = 0; i < count; i++) { arrayVar = [monLessonArrayA objectAtIndex:i]; for(i = 0; i <count; i ++){arrayVar = [monLessonArrayA objectAtIndex:i]; } }

I get an error saying i is undeclared, how can I set the objectAtIndex to i so I can loop through increasing it each time? 我得到一个错误,说我是未申报的,我怎么能将objectAtIndex设置为i所以我可以循环增加它每次?

Thanks. 谢谢。

Because your i is undeclared. 因为你的未申报。

for (int i = 0; i < count; i++)

Also, you don't need the * for your NSInteger . 此外,您的NSInteger不需要*

NSInteger count = [monLessonArrayA count]; 

在循环中使用它之前,您只是忘了声明i (及其数据类型):

for (int i = 0; i < count; i++) {

You can also use fast enumeration, which is actually faster: 您还可以使用快速枚举,这实际上更快:

for (id someObject in monLessonArrayA) {
    // Do stuff
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM