可变数组继承不可变数组
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//可变数组继承不可变数组
//1.创建 设定元素个数进行创建
NSMutableArray *mutArr=[NSMutableArray arrayWithCapacity:7];
//2.向数组中添加一个元素
NSArray *arr=@[@"MON",@"TUE",@"WED",@"THU",@"FRI",@"SAT",@"SUN"];
//把不可变数组写入到可变数组
NSMutableArray *mutarray=[NSMutableArray arrayWithArray:arr];
[mutarray addObject:@"EIG"];
//3.根据指定下标插入元素
[mutarray insertObject:@"NINE" atIndex:5];
//4.删除最后一个元素
[mutarray removeLastObject];
//5.根据指定下标删除元素
[mutarray removeObjectAtIndex:7];
//6.根据指定对象进行删除
[mutarray removeObject:@"SUN"];
//7.替换指定下标的元素
[mutarray replaceObjectAtIndex:0 withObject:@"SUN"];
for (id str in mutarray) {
NSLog(@"%@",str);
}
}
return 0;
}