首页 > 编程语言 > 详细

enumerateObjectsUsingBlock、enumerateObjectsWithOptions、enumerateObjectsAtIndexes、makeObjectsPerfor使用

时间:2015-07-02 09:58:32      阅读:1128      评论:0      收藏:0      [点我收藏+]

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、enumerateObjectsWithOptions、enumerateObjectsAtIndexes、makeObjectsPerfor使用

原文:http://www.cnblogs.com/yxwkf/p/4615158.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!