开发者

Loop through NSArray objectAtIndex

NSInteger *count = [monLessonArrayA count]; 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?

Thanks.


Because your i is undeclared.

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

Also, you don't need the * for your NSInteger.

NSInteger count = [monLessonArrayA count]; 


You just forgot to declare i (and its data type) before using it in the loop:

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


You can also use fast enumeration, which is actually faster:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜