NSArray 长用方法

2.1 NSArray

2.1.1方法

<1>常见创建方法

- (id)initWithObjects:(id)firstObj, ... ;

+ (id)arrayWithObjects:(id)firstObj, ... ;

<2>获取数组元素个数

- (NSUInteger)count;

<3>通过索引获取相应的元素

- (id)objectAtIndex:(NSUInteger)index;

<4>通过对象地址获取在数组中的索引

- (NSUInteger)indexOfObject:(id)anObject;

<5>判断数组中数组包含元素anObject

- (BOOL)containsObject:(id)anObject;

<6>获取数组的最后一个元素

- (id)lastObject;

<7>把数组元素内容按照字符串separator进行拼接

- (NSString *)componentsJoinedByString:(NSString *)separator;

 

2.2NSMutableArray

2.2.1方法

<1>增加数组元素

//追加元素

      - (void)addObject:(id)anObject;

//指定索引插入元素

  - (void)insertObject:(id)anObject atIndex:(NSUInteger)index;

    //追加一个数组

  - (void)addObjectsFromArray:(NSArray *)otherArray;

  <2>删除

//删除最后一个元素

  - (void)removeLastObject;

//删除指定索引的元素

  - (void)removeObjectAtIndex:(NSUInteger)index;

//删除所有元素

  - (void)removeAllObjects;

//在一定范围删除指定的元素

  - (void)removeObject:(id)anObject inRange:(NSRange)range;

//删除指定的元素

  - (void)removeObject:(id)anObject;

//根据一个数组删除指定的元素

  - (void)removeObjectsInArray:(NSArray *)otherArray;

  <3>修改数组

    - (void)setArray:(NSArray *)otherArray;

  <4>替换指定索引的元素

  - (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject;

  <5>交换数组元素

  - (void)exchangeObjectAtIndex:(NSUInteger)idx1 withObjectAtIndex:(NSUInteger)idx2;

转载于:https://www.cnblogs.com/xzguo/p/4753518.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值