遍历数组—三种内置的方法
来源:互联网 发布:cf网络异常的解决办法 编辑:程序博客网 时间:2024/06/08 02:52
NSMutableString *string1 = [NSMutableString initWithFormat:@"Tom"]; NSMutableString *string2 = [NSMutableString initWithFormat:@"Harry"]; NSMutableString *string3 = [NSMutableString initWithFormat:@"Jack"]; NSArray *array = [NSArray arrayWithObjects:string1,string2,string3, nil]; way1- 枚举 // 创建的 s 的类类型必须和需要被枚举的数组中的元素的类型保持一致 for ( NSString *s in array ){ NSLog(@"The string is %@.", s); } 结果: The string is Tom. The string is Harry. The string is Jack. way2- 使用 selector (选择器) [array makeObjectsPerformSelector:@selector(appendingString:) withObject:@"-student"]; way3- 使用块定义 [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){NSLog(@"The object(%lu)'s description is %@.", idx, [obj description]); }]; 在方法2 执行后,再执行方法3的结果: The object(1)'s description is Tom-student. The object(2)'s description is Harry-student. The object(3)'s description is Jack-student.
0 0
- 遍历数组—三种内置的方法
- php遍历数组的三种方法
- js数组遍历的三种方法
- OC中数组、字典的遍历的三种方法
- [php] PHP中遍历关联数组的三种方法
- php遍历关联数组的三种方法
- 黑马程序员---OC 中数组遍历的三种方法
- PHP遍历数组的代码,三种方法
- 数组遍历的三种方法以及数组排序的sort方法
- 遍历数组的三种方式
- php 数组的三种遍历
- Swift遍历数组的三种方式
- 数组遍历的三种方式
- 遍历整型数组的三种方式
- 遍历字符串数组的三种fangfa
- List数组的三种遍历方式
- php学习(三)遍历数组的方法
- 数组的遍历方法
- 一个基于RSA算法的Java数字签名例子
- RHEL 5基础篇—Linux常用命令参考手册
- KVC (Key-Value Coding)
- STM32单片机学习---PWM输出
- 欢迎大家关注我的微信帐号!
- 遍历数组—三种内置的方法
- 使用ajax提交必须alert才能赋值
- 高校平台--环境理解之Persistence Context
- 为仿真器添加eCos多线程调试支持,GDBServer Extender 0.0.1 使用说明
- 解释器模式
- sql 时间段的提取
- 类的对象定义和使用(含指针对象)
- 数据库_jdbc_连接池(Tomcat创建)
- Opencv学习笔记(六):图像的平滑