NSArray *arrayM2 = @[@"1",@"2",@"3",@"4"];
//使用for循环遍历
for(int i =0;i<[arrayM2 count];i++){
NSLog(@"%@",arrayM2[i]);
}
//NSEnumerator遍历
NSEnumerator *enumeration = [arrayM2 reverseObjectEnumerator];
NSString *object;
while ((object = [enumeration nextObject])!=nil) {
NSLog(@"%@", object);
}
//for...In遍历
for(id obj in arrayM2){
NSLog(@"%@",obj);
}
//block遍历
[arrayM2 enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"%@",obj);
}];
//GCD遍历处理耗时比较长,迭代次数较多的情况//经过测试运行遍历是无序的
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
dispatch_apply(arrayM2.count, queue, ^(size_t index) {
NSLog(@"%@--%@",arrayM2[index],[NSThread currentThread]);
});