I gotta question.
Suppose you have an array NSMutableArray myArray; and it has nome objects.
I can say:
for (NSObject* anObject in myArray){
//bla-bla
}
I can also say:
for (int i = 0; i < myArray.count-1; i ++){
//bla-bla
}
-
What is the difference between the 2 approaches?
-
Which way is faster?
Any advice (or link, or tut) is appreciated.
Cheers
Both versions shouldn’t be too different, especially not noticeably (with the exception of the second code not iterating over all items). If speed is everything you want, you can enumerate the array concurrently using
enumerateObjectsWithOptions:usingBlock:and passing theNSEnumerationConcurrentoption. However, beside of that, using either of the two versions won’t make a difference, so you should use whatever you like more. The first version is certainly less type intensive and also works for the other foundation container types (NSSet,NSCountedSet,NSDictionary)