Josh Kahane
Josh Kahane

Reputation: 17169

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.

Upvotes: 3

Views: 7146

Answers (3)

Douwe Maan
Douwe Maan

Reputation: 6878

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

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

Upvotes: 1

BoltClock
BoltClock

Reputation: 724572

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

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

Upvotes: 3

Calvin
Calvin

Reputation: 8775

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]; 

Upvotes: 7

Related Questions