IOS学习之NSArray和NSMutableArray详解
来源:互联网 发布:用友软件使用说明 编辑:程序博客网 时间:2024/06/05 15:42
关于IOS的开发过程中对于数据的处理主要涉及到字典(dictionary),数组(array),字符串(string)的操作是最多的,所以很有必要对这三个家伙搞熟悉来!
今天先给大家带来数组的使用
个人认为关于数据的操作无非就是查 插 该 删的操作,所以掌握好中心就可以更快的熟悉啦!
首先针对NSArray的操作
首先是初始化操作
NSArray *array = [[NSArray alloc] array]; // creats and returns an empty array
array = [NSArray arrayWithObjects:@"ceshi",@"test",nil]; //ending with nil
array = [NSArray arrayWithArray:array1];
//creats and ruturns an array containing the objects in another given array
+(NSArray *)arrayWithContentsOfFile:(NSString *)path
//creats and returns an array containing the contents of file specified by a given path
//通过给的路径将该文件的内容创建并返回一个数组
//其中的path是由通过writeToFile:atomically:方法产生的路径值
+(NSArray *)arrayWithContentsOfURL:(NSURL *)url
//creates and returns an array containing the contents specified by a given URL
//创建并返回由给定的URL指定的内容数组
+(instanceType)arrayWithObject:(id)anObject
//creates and returns an array containing a given object
//创建并返回由给定对象所组成的数组
数组查询操作(Querying an Array)
-(BOOL)containsObject:(id)object
//Returns a Boolean value that indicates whether a given object is present in the array
//判断所给定的对象是否存在数组中
@property(readonly) NSUInteger count
//the number of objects in the array
@property(nonatomic,readonly) id firstobject
//the first object in the array(read-only)
@property(nonatomic,readonly) id lastObject
//the last object in the array
-(id)objectAtIndex:(NSUInteger)index
//returns the object located at the specified index
-(NSEnumerator *)objectEnumerator
//an enumerator object that lets you access each object in the array
//返回数组对象的枚举
-(NSUInteger)indexOfObject:(id)anObject
//returns the lowest index whose corresponding array value is equal to a given object
//返回最先出现给定对象所对应的索引值
比较
-(BOOL)isEqualToArray:(NSArray *)otherArray //判断两个数组是否相等
-(BOOL)writeToFile:(NSString *)path automically:(BOOL)flag //将数组的内容写进指定的路径中的文件
-(BOOL)writeToURL:(NSURL*)url atomically:(BOOL)flag //将数组的内容写入指定的特殊的URL
下面来介绍下NSMutableArray
首先也是初始化的操作
+(instanceType)arrayWithCapacity:(NSUinteger)numItems //初始化可变数组的容量(分配内存)
+(NSMutableArray*)arrayWithContentOfFile:(NSString *)path
+(NSMutableArray *)arrayWithContentsOfURL:(NSURL *)url
添加操作
-(void)addObject:(id)object //inserts a given object at the end of the array
-(void)addObjectsFromArray:(NSArray *)otherArray
//Adds the objects contained in another given array to the end of the receving array's content
-(void)insertObject:(id)anObject atIndex:(NSUInteger)index
//inserts a given object into the array's contents at a given index
移除对象
-(void)removeAllObjects //Empties the array of all its elements
-(void)removeLastObject //Removes the object with the highest-vlaues index in the array
-(void)removeObject:(id)anObject //Removes all occurrences in the array of a given object
-(void)removeObjectAtIndex:(NSUinteger)index //Removes the object at index
替换对象
-(void)replaceObjectAtIndex:(NSUinteger)index withObject:(id)anobject
//Replaces the object at index with anObject
-(void)setArray:(NSArray*)otherArray
//sets the receiving array's elements to those in another given array
暂时先总结到这来,希望自己可以好好加油,将IOS搞定
- IOS学习之NSArray和NSMutableArray详解
- 【学习ios之路:Objective-C】NSArray和NSMutableArray
- IOS SDK详解之NSArray/NSMutableArray
- 二、IOS SDK详解之NSArray/NSMutableArray
- IOS开发之----NSArray和NSMutableArray
- Foundation框架学习之NSArray和NSMutableArray
- iOS之Object-C基础编程之NSArray和NSMutableArray
- 温故而知新之NSArray 和 NSMutableArray
- Foundation 之 NSArray和NSMutableArray
- iOS学习第九篇 —— NSArray 和 NSMutableArray
- iOS学习笔记3-NSArray 和 NSMutableArray
- iOS开发之NSArray和NSMutableArray的用法
- ios NSArray和NSMutableArray的常用方法
- oc学习之NSArray与NSMutableArray数组
- Objective-C学习-数组 NSArray 和 NSMutableArray
- Objective-C语法之NSArray和NSMutableArray
- Objective-C语法之NSArray和NSMutableArray
- Objective-C语法之NSArray和NSMutableArray
- 4 款消息队列软件产品大比拼
- Swift learn 3
- three.js 源码注释(二十五)Core/Geometry.js
- 【C++】趴一趴程序内存管理
- MySQL 高可用架构在业务层面的分析研究
- IOS学习之NSArray和NSMutableArray详解
- 【乐易考看在线】上市公司纷纷跨界押宝 在线教育能否成上市公司转型跳板
- BZOJ 3721 PA 2014 Final Bazarek 贪心
- 查看SELinux状态技巧与SELinux关闭方法
- Java 7 Fork/Join 框架
- 导航栏闪烁问题解决归纳
- 【仅支持移动设备】Swipe.JS轻量级移动幻灯效果
- Java编程风格
- 第13周项目2成绩处理