黑马程序员技术交流社区
标题: NSArray的常见方法 [打印本页]
作者: huguozhang 时间: 2015-7-17 02:51
标题: NSArray的常见方法
本帖最后由 huguozhang 于 2015-7-17 02:55 编辑
NSArray的常见方法:
- (NSUInteger)count;获取集合元素个数
- (id)objectAtIndex:(NSUInteger)index;获得index位置的元素, 等价于array[index];-(BOOL)containsObject: (id)anObject;是否包含某一个元素
- (id)lastObject;返回最后一个元素
- (id)firstObject;返回最后一个元素
-(NSUInteger)indexOfObject[size=14.6666669845581px]: (id)anObject;查找anObject元素在数组中的位置(如果找不到,返回-1)NSNotFound
-(NSUInteger)indexOfObject[size=14.6666669845581px]:(id)anObject inRange[size=14.6666669845581px]:(NSRange)range;在range范围内查找anObject元素在数组中的位置
- (void)makeObjectsPerformSelector[size=14.6666669845581px]:(SEL)aSelector;
- (void)makeObjectsPerformSelector[size=14.6666669845581px]:(SEL)aSelector withObject[size=14.6666669845581px]:(id)argument;
NSArray遍历元素
* 遍历, 就是将NSArray里面的所有元素一个一个取出来查看
* 常见的遍历方式有
*普通遍历
for (int i = 0; i<array.count; i++) { }
*快速遍历
for (id obj in array) { }
*Block遍历
[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { }];
作者: peng_gavin 时间: 2015-7-17 06:41
遍历很重要哦,楼主总结的不错
作者: 2899028818 时间: 2015-7-17 08:19
总结的很全面。。。。。。
| 欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) |
黑马程序员IT技术论坛 X3.2 |