NSObject *obj=[[NSObject alloc]init];
       NSArray *array=[[NSArray alloc] initWithObjects:@"abc",obj,@"cde",@"opq",@25, nil];
       //方法1 随便
       //int i=0;
       //int len=(int)array.count;
       //for(;i<len;++i){
       //    NSLog(@"method1:index %i is %@",i,[array objectAtIndex:i]);
       //}
       /*结果:
        method1:index 0 is abc
        method1:index 1 is <NSObject: 0x100106de0> method1:index 2 is cde
        method1:index 3 is opq
        method1:index 4 is 25
        */
       
   
       
       //方法2 好high
       //for(id obj in array){
       //    NSLog(@"method2:index %zi is %@",[array indexOfObject:obj],obj);
       //}
       /*结果:
        method2:index 0 is abc
        method2:index 1 is <NSObject: 0x100602f00> method2:index 2 is cde
        method2:index 3 is opq
        method2:index 4 is 25
        */
       
       //方法3,利用代码块方法 不知道
       //[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
       //    NSLog(@"method3:index %zi is %@",idx,obj);
       //    if(idx==2){//当idx=2时设置*stop为YES停止遍历
       //        *stop=YES;
       //    }
       //}];
       /*结果:
        method3:index 0 is abc
        method3:index 1 is <NSObject: 0x100106de0> method3:index 2 is cde
        */
       //方法4,利用迭代器 推荐
       //NSEnumerator *enumerator= [array objectEnumerator];//获得一个迭代器
       NSEnumerator *enumerator=[array reverseObjectEnumerator];//获取一个反向迭代器 //
       //NSLog(@"all:%@",[enumerator allObjects]);//获取所有迭代对象,注意调用完此方法迭代器就遍历完了,下面的nextObject就没有值了
       id obj2=nil;
       while (obj2=[enumerator nextObject]) {
           if([obj2 length] > 2){//只是一个示例,可以加入条件进行选择
               NSLog(@"method4:%@",obj2);
           }
       }
       /*结果:
        method4:25
        method4:opq
        method4:cde
        method4:<NSObject: 0x100106de0> method4:abc
        */
 

NSArray 迭代的更多相关文章

  1. 遍历NSArray, NSDictionary, NSSet的方法总结

    1,for循环读取 NSArray: NSArray *array = /*…*/ ; i<array.count; i++) { id object = array[i]; // do sth ...

  2. IOS - Objective-C NSArray和NSMutableArray的详解 使用

    原文地址:http://blog.csdn.net/totogo2010/article/details/7729377 Objective-C的数组比C++,Java的数组强大在于,NSArray保 ...

  3. iOS开发实用技巧—Objective-C中的各种遍历(迭代)方式

    iOS开发实用技巧—Objective-C中的各种遍历(迭代)方式 说明: 1)该文简短介绍在iOS开发中遍历字典.数组和集合的几种常见方式. 2)该文对应的代码可以在下面的地址获得:https:// ...

  4. iOS 学习 - 6.Objective-C中的各种遍历(迭代)方式

    说明:转自文顶顶 一.使用 for 循环 要遍历字典.数组或者是集合,for 循环是最简单也用的比较多的方法 -(void)iteratorWithFor { //////////处理数组////// ...

  5. Objective-C语法之NSArray和NSMutableArray

    转自:http://www.cnblogs.com/stoic/archive/2012/07/09/2582773.html Objective-C的数组比C++,Java的数组强大在于,NSArr ...

  6. ios开发 数据库版本迁移手动更新迭代和自动更新迭代

    数据库版本迁移顾名思义就是在原有的数据库中更新数据库,数据库中的数据保持不变对表的增.删.该.查. 数据持久化存储: plist文件(属性列表) preference(偏好设置) NSKeyedArc ...

  7. Objective-C中NSArray和NSMutableArray是如何使用的?

    Objective-C的数组比C++,Java的数组强大在于,NSArray保存的对象可以是不同的对象.但只能保存对象,int ,char,double等基本数据类型不能直接保存,需要通过转换成对象才 ...

  8. 用法总结:NSArray,NSSet,NSDictionary-备用

    Foundation framework中用于收集cocoa对象(NSObject对象)的三种集合分别是: NSArray 用于对象有序集合(数组)NSSet 用于对象无序集合      (集合)NS ...

  9. 7、Objective-C中的各种遍历(迭代)方式

    一.使用for循环 要遍历字典.数组或者是集合,for循环是最简单也用的比较多的方法,示例如下: //普通的for循环遍历 -(void)iteratorWithFor { //////////处理数 ...

随机推荐

  1. Global::validateEmail

    /***************************************************************** (C) Copyright DENTSPLY Internatio ...

  2. apache+tomcat整合

    一 .Apache与Tomcat的比较 apache支持静态页面,tomcat支持动态的,比如servlet等. 一般使用apache+tomcat的话,apache只是作为一个转发,对jsp的处理是 ...

  3. Python计算斗牛游戏的概率

    Python计算斗牛游戏的概率 过年回家,都会约上亲朋好友聚聚会,会上经常会打麻将,斗地主,斗牛.在这些游戏中,斗牛是最受欢迎的,因为可以很多人一起玩,而且没有技术含量,都是看运气(专业术语是概率). ...

  4. Jquery LigerUI框架学习(二)之Tree于Tab标签实现iframe功能

    LigerUI框架Tree于Tab标签动态使用,当点击Tree后动态创建Tab标签,和通常用的iframe框架功能类似 Tree中的关键代码 //Tree初始化 $("#tree1" ...

  5. Redis 三:存储类型之字符串

    .赋值单个: [赋值多个:mset a b c ] .取值单个: get a [取值多个:mget a b c] .数字递增 incr a 在a的基础上+,那就是返回101 如果预先的值为0,那么返回 ...

  6. Setting composer minimum stability for your application

    Do you have a confusion of how do you determine the stability when using composer dependency manager ...

  7. CHROME下去掉保存密码后输入框变成黄色背景样式

    之前没遇到过这种情况,现在打开这个页面后,手机号和密码都已经输入了,而且还显示的是黄色背景,清了下cookie,没有解决问题.请教了下大神,先把方法整理到这儿. 用代码审查看了input样式有如下样式 ...

  8. matlab实现雅可比、高斯塞德尔、后项误差计算

    稀疏矩阵生成: function [a, b] = aparsesetup(n) e = ones(n, 1); n2 = n / 2; a = spdiags([-e 3*e -e], -1:1, ...

  9. PHP获取mysql数据表的字段名称和详细信息的方法

    首先我们需要了解下查询MySQL数据库/表相关信息的SQL语句: 代码如下: SHOW DATABASES                                //列出 MySQL Serv ...

  10. google api , using a refresh token to get the access token

    router.get('/refresh',function(req,res){ oauth2Client.credentials = { refresh_token: '1/RqVyL7yLBxws ...