循环遍历NSArray中的objectAtIndex。

3

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

我收到一个错误信息,说 i 未声明。如何将对象的索引设置为 i,以便我可以循环并每次增加它?

谢谢。

3个回答

7
因为你的 i 没有声明。
for (int i = 0; i < count; i++)

此外,您的 NSInteger 不需要使用 *
NSInteger count = [monLessonArrayA count]; 

3

在循环中使用变量i之前,您忘记了声明它(以及它的数据类型):

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

1

你也可以使用快速枚举,它实际上更快:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接