I'm trying to reverse a for loop in xcode.
for (enemyBullet *b in bullets)
{
}
can someone help ?
thanks
I'm trying to reverse a for loop in xcode.
for (enemyBullet *b in bullets)
{
}
can someone help ?
thanks
NSEnumerator *enu = [bullets reverseObjectEnumerator];
enemyBullet *b = nil;
while (b = [enu nextObject]) {
// do your stuff here
}
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.