• Object-C-NSArray


    NSArray *fruitArray=[[NSArray alloc] initWithObjects:@"apple",@"banana",@"pear",nil];开辟一个不可变的数组

    NSString *obj=[fruitArray objectAtIndex:1];

    NSArray *names=@[@"tom",@"jack",@"maggie"];

    NSMutableArray *languages=[NSMutableArray array];

    [languages addObject:@"c++"];

    [languages addObject:@"Objc"]; 添加元素

    [languages insertObject:@"swift" atIndex:1];

    [languages removeObject:@"c++"];

    [languages removeAllObjects];

    [languages removeObjectAtIndex:0];

    [languages replaceObjectAtIndex:0 withObject:@"c#"];

     1 数组:
     2         //1.不可变数组
     3 //        NSArray *fruitArr = [[NSArray alloc]initWithObjects:@"apple",@"banana",@"pear",@"watermelon",@"longan",nil];
     4 //        NSLog(@"%@",fruitArr);
     5 //        NSLog(@"%lu",[fruitArr count]);
     6 //        NSString *obj = [fruitArr objectAtIndex:2];
     7 //        NSLog(@"%@",obj);
     8 //
     9 //        NSArray *appleArr = [NSArray arrayWithObjects:@"apple",@"banana",@"pear",nil];
    10 //        NSLog(@"%@",appleArr);
    11 //
    12 //        NSArray *names = @[@"tom",@"jack",@"kitty"];
    13 //        NSLog(@"%@",names);
    14         
    15         //2.可变数组
    16          NSMutableArray *languages=[NSMutableArray array];
    17         [languages addObject:@"c++"];
    18         [languages addObject:@"oc "];
    19         [languages addObject:@"java"];
    20         [languages addObject:@"php"];
    21         NSLog(@"%@",languages);
    22         [languages insertObject:@"swift" atIndex:1];
    23         NSLog(@"%@",languages);
    24         [languages removeObject:@"php"];
    25         [languages removeObjectAtIndex:0];
    26         [languages replaceObjectAtIndex:1 withObject:@"c#"];
    27         NSLog(@"%@",languages);
    28         
    29         //数组的遍历
    30 //        for (int i=0; i<[languages count]; i++) {
    31 //            NSLog(@"第%d个对象:%@",i+1,[languages objectAtIndex:i]);
    32 //        }
    33         //
    34         for (NSString *obj in languages) {
    35             NSLog(@"%@",obj);
    36         }
    View Code

    ie

  • 相关阅读:
    Day15模块(导入,使用)
    day14 迭代器,生成器,函数的递归调用
    Day13有参装饰器,三元表达式,匿名函数
    re模块
    Day12装饰器
    subprocess模块windows系统命令和linux系统命令
    Day11名称空间,作用域,闭包函数
    识别 Linux上的设备(磁盘)类型
    Linux lsblk和df命令区别
    Linux远程拷贝scp
  • 原文地址:https://www.cnblogs.com/Opaser/p/4554749.html
Copyright © 2020-2023  润新知