zoukankan      html  css  js  c++  java
  • ios 遍历数组的方法

    //第一种
    [arr enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *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,%@",index,[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]);
    }
    
    
    //第八中
    NSEnumerator *enumerator = [langArray objectEnumerator];  
    id object;  
    while ((object = [enumerator nextObject]) != nil) {  
         NSLog(@"langArray=%@", object);  
    } 
  • 相关阅读:
    R
    R 包的安装,使用,更新
    R 安装 简单实用
    R 介绍
    mongo:用户管理
    MySQL 书籍
    mongo: 索引
    blog
    游标处理
    如何在ASP.NET的web.config配置文件中添加MIME类型
  • 原文地址:https://www.cnblogs.com/KingQiangzi/p/4252796.html
Copyright © 2011-2022 走看看