NSMutableArray 可变数组的使用

NSMutableArray 是 NSArray 的一个子类,因此可以在任何使用 NSArray 的位置使用 NSMutableArray。

除了包含在 NSArray 中的方法,NSMutableArray 还提供了修改数组的方法。

//向数组添加对象

addObject: 和 insertObject:atIndex: 

//从数组删除对象

removeAllObjects、removeLastObject 和 removeObjectAtIndex: 

//替换数组中的某个对象

replaceObjectAtIndex:withObject: 

//筛选数组

filterUsingPredicate:

//重新排列数组中的元素

exchangeObjectAtIndex:withObjectAtIndex:、sortUsingComparator:和sortUsingFunction: context:

ps:

数组类 NSArray 和 NSMutableArray 仅能包含对象。

不能将标量数据类型,如 int、long 或者其他任何不是继承自 NSObject 的类型插入 NSArray 或 NSMutableArray。


你可能感兴趣的:(NSMutableArray 可变数组的使用)