enumerateObjectsUsingBlock、enumerateObjectsWithOptions、enumerateObjectsAtIndexes、makeObjectsPerfor使用
2015-07-02 09:21
936 查看
OC至 NSArray它提供了一个方便的遍历block,以下具体说明
第一、enumerateObjectsUsingBlock
NSArray *array=@[@"aa",@"bb",@"cc",@"dd",@"ee",@"ff",@"gg"];
[array
enumerateObjectsUsingBlock:^(id obj,
NSUInteger idx, BOOL *stop) {
NSLog(@"%@",obj);
}];
idx代表索引值,obj代表遍历内容
第二、enumerateObjectsWithOptions
NSEnumerationReverse表示逆序遍历
[array
enumerateObjectsWithOptions:NSEnumerationReverse
usingBlock:^(id obj,
NSUInteger idx, BOOL *stop) {
NSLog(@"%@",obj);
}];
第三、enumerateObjectsAtIndexes
该函数不但能够指定遍历顺序。还能够指定遍历的空间
[array
enumerateObjectsAtIndexes:[NSIndexSet
indexSetWithIndexesInRange:NSMakeRange(2,
3)] options:NSEnumerationConcurrent
usingBlock:^(id obj,
NSUInteger idx, BOOL *stop) {
NSLog(@"%@",obj);
}];
第五、- (void)makeObjectsPerformSelector:(SEL)aSelector;
让数组中的每一个元素 都调用 aMethod
第六、让数组的每一个元素运行aSelector,传入的參数是argument
- (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)argument;
第一、enumerateObjectsUsingBlock
NSArray *array=@[@"aa",@"bb",@"cc",@"dd",@"ee",@"ff",@"gg"];
[array
enumerateObjectsUsingBlock:^(id obj,
NSUInteger idx, BOOL *stop) {
NSLog(@"%@",obj);
}];
idx代表索引值,obj代表遍历内容
第二、enumerateObjectsWithOptions
NSEnumerationReverse表示逆序遍历
[array
enumerateObjectsWithOptions:NSEnumerationReverse
usingBlock:^(id obj,
NSUInteger idx, BOOL *stop) {
NSLog(@"%@",obj);
}];
第三、enumerateObjectsAtIndexes
该函数不但能够指定遍历顺序。还能够指定遍历的空间
[array
enumerateObjectsAtIndexes:[NSIndexSet
indexSetWithIndexesInRange:NSMakeRange(2,
3)] options:NSEnumerationConcurrent
usingBlock:^(id obj,
NSUInteger idx, BOOL *stop) {
NSLog(@"%@",obj);
}];
第五、- (void)makeObjectsPerformSelector:(SEL)aSelector;
让数组中的每一个元素 都调用 aMethod
第六、让数组的每一个元素运行aSelector,传入的參数是argument
- (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)argument;
相关文章推荐
- object-c计划tips-添加到类对象属性
- Objective-C 的“多继承”
- Objective-C语法之KVC的使用
- [学习笔记—Objective-C]《Objective-C 程序设计 第6版》第七章 类
- Objective-C 深拷贝与浅拷贝
- OC基础4:类和方法
- Objective-C(七、分类和延展)——iOS开发基础
- OC基础3:一些基本概念
- [Objective-C] BOOL类型
- Java NIO框架Netty教程(九) Object对象编/解码
- Java NIO框架Netty教程(十) Object对象的连续收发解析分析
- Java NIO框架Netty教程(八) Object对象传递
- Eclipse UML 工具 ObjectAid 介绍
- 黑马程序员——Objective-C语言知识整理——构造方法相关知识总结
- 黑马程序员——Objective-C语言知识整理——匿名类与self/super关键字
- AS3 复制Object
- Objective-C的Runtime System
- Objective-C中@property的所有属性详解
- [Objective-C] 通过匿名category给category添加成员变量
- [Objective-C] 使用Category给类添加private方法