enumerateObjectsUsingBlock、enumerateObjectsWithOptions、enumerateObjectsAtIndexes、makeObjectsPerfor使用

enumerateObjectsUsingBlock、enumerateObjectsWithOptions、enumerateObjectsAtIndexes、makeObjectsPerfor使用

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

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;

版权声明:本文博客原创文章。博客,未经同意,不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117690.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号