zoukankan      html  css  js  c++  java
  • enumerateObjectsUsingBlock、enumerateObjectsWithOptions、enumerateObjectsAtIndexes、makeObjectsPerfor使用

    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;


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

  • 相关阅读:
    类成员之静态字段和普通字段、静态方法和普通方法
    类的导出
    面向对象之继承
    面向对象之封装
    面向对象与函数式的对比
    计算器
    模拟信用卡登录程序
    /etc/fstab
    解决 Your project contains error(s),please fix them before running your applica ..
    C#之SqlDependency数据库缓存
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4615158.html
Copyright © 2011-2022 走看看