可变数组NSMutableArray简介(可变数组必须初始化,增加、删除均可)
NSMutableArray *marr1 = [NSMutableArray arrayWithCapacity:10];
[marr1 addObject:@"abc"];//添加一个对象
[marr1 addObject:@"bcd"];
NSLog(@"%@",marr1[0]);
[marr1 removeObject:@"abc"];//移除一个对象
NSLog(@"%@",marr1[0]);
//这样不可以(不能适用快速初始化方法)
//NSMutableArray * marr2 = @[@"111",@"222"];
//这样可以使用
NSMutableArray *marr3 = [NSMutableArray arrayWithArray:@[@"111",@"222"]];
NSLog(@"%@",marr3);
[marr3 addObject:@"333"];
NSLog(@"%@",marr3);
网友评论