IOS 之 NSArray 数组方法详解(4)

1、 向数组中添加一个对象
- (void)addObject:(id)anObject;


2、向数组中指定的index 位置,插入一个新的对象
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index;


3、移除数组的最后一个元素
- (void)removeLastObject;


4、移除指定为指定位置的元素
- (void)removeObjectAtIndex:(NSUInteger)index;


5、使用anObject 替换 下标为 index 位置上的元素
- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject;


6、使用一个数组给当前的数组添加元素
- (void)addObjectsFromArray:(NSArray *)otherArray;


7、交换指定 index1 和 index2 两个位置上的元素
- (void)exchangeObjectAtIndex:(NSUInteger)idx1 withObjectAtIndex:(NSUInteger)idx2;


8、 移除数组中的所有元素
- (void)removeAllObjects;


9、使用anObject 对象替换 range 位置上的元素,
相当于删除 range位置的元素,然后在把 anobject 插入到这个位置
- (void)removeObject:(id)anObject inRange:(NSRange)range;


10、如果指定的元素,如果元素不存在,则不移除
- (void)removeObject:(id)anObject;


11、 同9 相同
- (void)removeObjectIdenticalTo:(id)anObject inRange:(NSRange)range;


12、方法内容 和9 相同
- (void)removeObjectIdenticalTo:(id)anObject;


13、不建议使用
- (void)removeObjectsFromIndices:(NSUInteger *)indices numIndices:(NSUInteger)cnt NS_DEPRECATED(10_0, 10_6, 2_0, 4_0);


14、移除给定数组中的元素
- (void)removeObjectsInArray:(NSArray *)otherArray;


15、移除指定range  上的所有元素 
- (void)removeObjectsInRange:(NSRange)range;


16、使用otherArray 数组中 otherRange 位置上的元素,替换当前数组中 range 位置上的元素
- (void)replaceObjectsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray range:(NSRange)otherRange;


17 、 使用otherArray 数组上的位置,替换 range 上的元素
- (void)replaceObjectsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray;


18、对当前的数组排序,使用排序算法
- (void)sortUsingFunction:(NSInteger (*)(id, id, void *))compare context:(void *)context;


19、对当前的数组排序,使用排序算法
- (void)sortUsingSelector:(SEL)comparator;


20、在indexes 的位置上,插入一个数组
- (void)insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes;


21、移除制定indexes 位置上的元素
- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes;


22、使用一个对象数组,替换 indexes 位置上的 元素
- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects;


23
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx NS_AVAILABLE(10_8, 6_0);


24、排序
- (void)sortUsingComparator:(NSComparator)cmptr
25、 使用后面的元素进行排序
- (void)sortWithOptions:(NSSortOptions)opts usingComparator:(NSComparator)cmptr


25、 创建NSMutableArray 数组
+ (id)arrayWithCapacity:(NSUInteger)numItems;
- (id)initWithCapacity:(NSUInteger)numItems;

你可能感兴趣的:(IOS,相关)