问题
I see a macro CCARRAY_FOREACH in coccos2d, actually what does it? can we do alternative solution instead of it?i am using following code for spriteBatchNode?
CCARRAY_FOREACH([spriteBatch children], sprite)
{
...................
}
回答1:
it is a macro for looping through each object inside a CCArray... an alternative would be objective-c's foreach for (object in array)
that goes like this:
for (CCSprite *sprite in [spriteBatch children]) {
...
}
this is for NSArray and NSMutableArray but i think it should work fine for CCArray as well.
回答2:
The other answer is actually wrong. CCARRAY_FOREACH
isn't a macro for fast enumeration, it is a replacement for fast enumeration for CCArray
s. CCARRAY_FOREACH
is a tiny bit faster than fast enumeration on a NS(Mutable)Array
(about 10%), so better use it if you are using CCArray
s.
Check the CCArray.h
header to see what the macro actually is.
来源:https://stackoverflow.com/questions/4872855/what-is-ccarray-foreach-in-coccos2d