The speed of iteration does not depend on what type of data you store in the array. It is affected by the type of array used: there are significant differences between iterating through Objective-C NSArray(or any of its subclasses, for example NSMutableArray), a C-style array, or C ++ std::vector.
If you use NSArrayand use Objective-C 2.0 (for example, on iPhone or Mac OS X 10.5 or later), you can use fast enumeration to repeat, which is significantly faster than the old iteration style:
for(id object in myNSArray)
;
int count = [myNSArray count], i;
for(i = 0; i < count; i++)
{
id object = [myNSArray objectAtIndex:i];
}
, C- ++ std::vector s, , . , Objective-C: ( count objectAtIndex:) Objective-C, , .
C- ++ std::vector , :
SomeType *myArray = ...;
int i;
for(i = 0; i < myArraySize; i++)
;
std::vector<SomeType> myArray = ...;
for(std::vector<SomeType>::iterator i = myArray.begin(); i != myArray.end(); ++i)
;