zoukankan      html  css  js  c++  java
  • OC系列foundation Kit基础-NSMutableArray

    一.可变数组创建和不可变数组类似

    二.可变数组操作

    首先我们创建一个空的可变数组

    NSMutableArray *mArr = [[NSMutableArray alloc]init];
    

    1.添加元素

    [mArr addObject:@"one"];
    [mArr addObject:@"two"];
    [mArr addObject:@"three"];
            
    NSLog(@"mArr is %@",mArr);

    输出结果:

    2016-06-27 16:06:54.676 OcTest[964:728178] mArr is (
        one,
        two,
        three
    )
    Program ended with exit code: 0

    2.删除元素

    [mArr removeObject:@"one"];
    [mArr removeAllObjects];

    3.置换元素

    [mArr exchangeObjectAtIndex:0 withObjectAtIndex:2];

    三.应用实例:将字符串拆分成数组反向输出

    NSString *str = @"this is an Object-C program";
    NSArray *arr = [str componentsSeparatedByString:@" "];
    NSMutableArray *mArr = [[NSMutableArray alloc]init];
    NSEnumerator *enu = [arr reverseObjectEnumerator];
    id obj;
    while(obj = [enu nextObject]){
       [mArr addObject:obj];
    }
    NSLog(@"mArr is %@",mArr);
    

      输出结果:

    2016-06-27 16:16:45.198 OcTest[992:754324] mArr is (
        program,
        "Object-C",
        an,
        is,
        this
    )
    Program ended with exit code: 0
    未来的你会感谢今天努力的自己 ------Alen
  • 相关阅读:
    PHP对象
    MySQL多表更新
    使用not in的子查询
    MySQL比较运算符的子查询
    控制器调用函数
    MVC目录规范
    MVC流程
    mxnet安装
    离线安装Python包hickle,easydict
    深度学习基础
  • 原文地址:https://www.cnblogs.com/kaihuacheng/p/5616553.html
Copyright © 2011-2022 走看看