ios 遍历数组的方法

下面是来客网 jb51.cc 通过网络收集整理的代码片段。

来客网小编现在分享给大家,也给大家做个参考。

    //第一种  
    [arr enumerateObjectsUsingBlock: ^(id obj,NSUInteger idx,BOOLBOOL *stop){  
        NSLog(@"%ld,%@",idx,[arr objectAtIndex:idx]);  
    }];  
    //第二种  
    dispatch_apply([arr count],dispatch_get_global_queue(0,0),^(size_t index){//并行  
        NSLog(@"%ld,index,[arr objectAtIndex:index]);  
    });  
    //第三种  
    dispatch_apply([arr count],dispatch_get_main_queue(),^(size_t index){//串行,容易引起主线程堵塞,可以另外开辟线程  
        NSLog(@"%ld,[arr objectAtIndex:index]);  
    });  
    //第四种  
    for (NSString*str in arr) {  
         NSLog(@"%@",str);  
    }  
    //第五种,do-while  
    int i = 0;  
    do {  
        NSLog(@"%@",[arr objectAtIndex:i]);  
        i++;  
    } while (i<[arr count]); //第六种,while-do int j = 0; while (j<[arr count]) { NSLog(@"%@",[arr objectAtIndex:j]); j++; } //第七种,普通for循环 for (int m = 0; m<[arr count]; m++) { NSLog(@"%@",[arr objectAtIndex:m]); } 

注意:

以上是来客网(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。

以上是来客网为你收集整理的ios 遍历数组的方法全部内容,希望文章能够帮你解决ios 遍历数组的方法所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。