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.不可变数组
// NSArray *fruitArr = [[NSArray alloc]initWithObjects:@"apple",@"banana",@"pear",@"watermelon",@"longan",nil];
// NSLog(@"%@",fruitArr);
// NSLog(@"%lu",[fruitArr count]);
// NSString *obj = [fruitArr objectAtIndex:2];
// NSLog(@"%@",obj);
//
// NSArray *appleArr = [NSArray arrayWithObjects:@"apple",@"banana",@"pear",nil];
// NSLog(@"%@",appleArr);
//
// NSArray *names = @[@"tom",@"jack",@"kitty"];
// NSLog(@"%@",names); //2.可变数组
NSMutableArray *languages=[NSMutableArray array];
[languages addObject:@"c++"];
[languages addObject:@"oc "];
[languages addObject:@"java"];
[languages addObject:@"php"];
NSLog(@"%@",languages);
[languages insertObject:@"swift" atIndex:];
NSLog(@"%@",languages);
[languages removeObject:@"php"];
[languages removeObjectAtIndex:];
[languages replaceObjectAtIndex: withObject:@"c#"];
NSLog(@"%@",languages); //数组的遍历
// for (int i=0; i<[languages count]; i++) {
// NSLog(@"第%d个对象:%@",i+1,[languages objectAtIndex:i]);
// }
//
for (NSString *obj in languages) {
NSLog(@"%@",obj);
}
ie