Ios array Traversal method
Currently, seven methods are available.
// The first [arr enumerateObjectsUsingBlock: ^ (id obj, NSUInteger idx, BOOL * stop) {NSLog (@ "% ld, % @", idx, [arr objectAtIndex: idx]) ;}]; // The second dispatch_apply ([arr count], dispatch_get_global_queue (0, 0), ^ (size_t index) {// parallel NSLog (@ "% ld, % @", index, [arr objectAtIndex: index]) ;}); // The third dispatch_apply ([arr count], dispatch_get_main_queue (), ^ (size_t index) {// serial, which may easily cause congestion of the main thread. You can also open up the thread NSLog (@ "% ld, % @", index, [arr objectAtIndex: index]) ;}); // type 4 for (NSString * str in arr) {NSLog (@ "% @", str );} // Category 5: do-while int I = 0; do {NSLog (@ "% @", [arr objectAtIndex: I]); I ++ ;} while (I <[arr count]); // type 6, while-do int j = 0; while (j <[arr count]) {NSLog (@ "% @", [arr objectAtIndex: j]); j ++;} // Class 7, General for loop for (int m = 0; m <[arr count]; m ++) {NSLog (@ "% @", [arr objectAtIndex: m]);}
I personally prefer the first method.
Note:
① The second method is parallel, so the printed items are random and not printed in order.
② The third type is likely to cause the main thread congestion, so it is best to create another thread on your own.
③ I am a little knowledgeable about these types of knowledge. Please add
③