There are currently seven ways to know
First Type [arr enumerateobjectsusingblock: ^ (id obj, Nsuinteger idx, BOOL *stop) {NSLog (@ "%ld,%@", Idx,[arr Objectati NDEX:IDX]); }]; The second type of dispatch_apply ([arr Count], dispatch_get_global_queue (0, 0), ^ (size_t index) {//Parallel NSLog (@ "%ld,%@", Index,[a RR Objectatindex:index]); }); The third type of dispatch_apply ([arr Count], Dispatch_get_main_queue (), ^ (size_t index) {//serial, easy to cause the main thread to clog, can also open threads NSLog (@ "%ld ,%@ ", Index,[arr Objectatindex:index]); }); Fourth type for (Nsstring*str in arr) {NSLog (@ "%@", str); }//fifth type, do-while int i = 0; do {NSLog (@ "%@", [arr objectatindex:i]); i++; } while (I<[arr Count]); The sixth type, while-do int j = 0; while (J<[arr Count]) {NSLog (@ "%@", [arr objectatindex:j]); j + +; }//Seventh type, normal for loop for (int m = 0; M<[arr count]; m++) {NSLog (@ "%@", [arr objectatindex:m]); }
Personally prefer the first method
Attention:
① the second method is parallel, so the printed stuff is random, not printed in sequence.
② third is prone to clogging the main thread, so it's best to create a different thread yourself
③ I learned shallow, now know on these kinds of, welcome to add
③
How iOS iterates through arrays