NSMutableArray继承自NSArray
查用方法
//初始化5个位置NSMutableArray *marray= [NSMutableArray arrayWithCapacity:5];//添加一个元素[marray addObejct:@"a"];//添加到指定下标处[marray insertObject:@"b" atIndex:0];//移除最后一个元素[marray removeLastObject];//移除指定元素[marray removeObect:@"a"];//移除指定下标元素[marray removeObejctAtIndex:0];//添加数组[marray addObectsFromArray:array];//替换指定下标元素[marray replaceObjectAtIndex:0 withObect:@"obj"];//移除所有元素[marray removeAllObjects];
遍历数组
NSArray *array = [NSArray arryWithObecjts:@"a",@"b",nil];for (int i = 0 ; i < [array length]; i++){ NSString *ele = [array objectAtIndex:i];}for (NSString *str in array){ NSLog(@"%@",str);}for (id str in array){ NSLog(@"%@",str);}