iOS基础学习

Objective-C基础学习之NSArray基本概念

2017-10-24  本文已影响12人  WenJim

1.NSArray的基本概念

2.NSArray的创建方式

3.NSArray 的使用注意事项

    NSArray *arr = [NSArray arrayWithObjects:@"cwj", nil ,@"abc",@"qqq", nil];
    NSLog(@"%@", arr);
输出结果:
(
    cwj
)

4.NSArray的常用方法

NSArray * arr = [NSArray arrayWithObjects:p,obj,@"cwj", nil];
NSLog(@"count = %lu",[arr count]);
NSArray * arr = [NSArray arrayWithObjects:p,obj,@"cwj", nil];
NSLog(@"arr[1]  = %@",[arr objectAtIndex:1]);
NSArray * arr = [NSArray arrayWithObjects:@"zs",@"ls",@"ww",@"cwj",@"zbc", nil];
    if ([arr containsObject:@"ls"]) {
        NSLog(@"arr中包含ls");
    }else{
        NSLog(@"arr中不包含ls");
    }
NSArray * arr = [NSArray arrayWithObjects:p,obj,@"cwj", nil];
NSLog(@"lastObject = %@",[arr lastObject]);
NSArray * arr = [NSArray arrayWithObjects:p,obj,@"cwj", nil];
NSLog(@"firstObject = %@",[arr firstObject]);

5.NSArray的简写形式

[NSArray arrayWithObjects:@"Jack", @"Rose", @"Jim", nil];
@[@"Jack", @"Rose", @"Jim"];
[array objectAtIndex:0];
array[0];
上一篇 下一篇

猜你喜欢

热点阅读