NSArray即oc里的数组,它可以保存不同的对象,但不能保存基本数据类型,int ,char,double等基本数据类型不能直接保存,需要通过转换成对象才能加入数组。
主要的方法如下:
1、创建
类方法:
arrayWithArray、arrayWithObjects:、arrayWithContentsOfFile:
实例方法:
initWithObjects:、initWithArray:、initWithContentsOfFile:
2、查询相关
containsObject:、count、firstObject、lastObject、objectAtIndex:、objectsAtIndexes:
3、比较数组
firstObjectCommonWithArray:、isEqualToArray:
NSMutableArray,即可变数组,可以对其进行插入、删除操作。主要方法如下:
1、创建
arrayWithCapacity:、initWithCapacity:
2、添加元素
addObject:、addObjectsFromArray:、insertObject:atIndex:、insertObjects:atIndexes:
3、删除元素
removeAllObjects、removeLastObject、removeObject:、removeObjectAtIndex:
4、替换元素
replaceObjectAtIndex:withObject:、replaceObjectsAtIndexes:withObjects: