tags:

views:

629

answers:

2

I'm trying to reverse a for loop in xcode.

for (enemyBullet *b in bullets)
{

}

can someone help ?

thanks

+5  A: 
NSEnumerator *enu = [bullets reverseObjectEnumerator];

enemyBullet *b = nil;

while (b = [enu nextObject]) {
    // do your stuff here
}
parceval
+4  A: 

Perspx's way will not utilize fast object enumeration. What you really want to do is:

NSEnumerator *bulletReverseObjectEnumerator = [bullets reverseObjectEnumerator];
for (enemyBullet *b in bulletReverseObjectEnumerator) {
   NSLog(@"DANCE BULLET DANCE: %@", b);
}

Concept being, fast object enumeration is several times faster than iterating with a flat while-loop.

Alex C Schaefer