- 首页 > it技术 > >
NSArray NSMutableArray NSString NSMutableString NSDictionary NSMutableDictionary常用增删查改
#program notice - 数组常用方法:(增删查改)//创建一个多对象数组
NSArray *array = [NSArray arrayWithObjects];
//从一个文件中读取一个数组
+ (NSArray *) arrayWithContentsOfFile:(NSString *)path;
//返回一个数组的元素个数
- (NSUInteger) count;
//根据index返回元素对象;
- (id) objectAtIndex:(NSUInteger)index;
//第一个元素对象
- (id) firstObject;
//最后一个元素对象
- (id) lastObject;
//判断两个数组元素内容是否相同
- (BOOL) isEqualToArray:(NSArray *)array;
#program notice - NSMutableArray//可变数组增加元素
- (void) addObject:(id)obj;
//移除index位置上的元素
- (void) removeObjectAtIndex:(NSUInteger)index;
//清空数组
- (void) removeAllObjects;
//移除最后一个元素对象
- (void) removeLastObject;
#program notice - NSMutableString methods;
//追加字符串
- (void) appendFormat:(NSString *)string;
//重置字符串
- (void) setString:(NSString *)string;
//格式化初始字符串
- (id) initWithFormat:();
//从文件中读取一个字符串
- (id) initWithContentsOfFile:(NSString *)path encoding:() error:;
//从URL中读取一个字符串
- (id) initWithContentsOfURL:(NSString *)URL encoding:() error:;
//获取字符串长度,字符个数
- (NSUInteger) length;
//返回C风格字符串
- (NSString *) UTF8String;
//格式化拼接字符串
- (NSString *) stringByAppendingFormat:();
//从index开始获取以后全部子串
- (NSString *) subStringFromIndex:(NSUInteger)index;
//获取子串直到index位置
- (NSString *) subStringToIndex:(NSUInteger)index;
-(NSString *) subStringWithRange:(NSRange)range;
//按指定分隔符分割字符串
- (NSArray *) componentsSeparatedByString:(NSString *)separateString;
#Program notice String Replace//替换字符串
- (NSString *) stringByReplacingOccurrencesOfString:(NSString *)string withString:(NSString *)string;
//范围替换字符串
- (NSString *) stringByReplacingOccurrencesOfString:(NSString *)string withString:(NSString *)string options:(NSEnum)enumVal range:(NSRange) range;
//比较俩字符串
- (NSCompareVal) compare:(NSString *)string;
//字符串是否以某个字符串开头
- (BOOL) hasPreFix:(NSString *)string;
//字符串是否以某个字符串结尾
- (BOOL) hasSuffix:(NSString *)string;
#Program NOTICE - Getting Numeric Values All Methods
#Program NOTIC - NSDictionary
//初始化多个 < value - key > 用nil结束录入 并且 key一定不能为空 ,若val要为空不能使用nil而要使用NSNull
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"val_1",@"key_1",@"val_2",
@"key_2",@"val_3",@"key_3",nil];
//返回字典KV个数
- (NSUInteger) count;
//取出所有key并放入数组
- (NSArray *) allKeys;
//返回所有Value的数组
- (NSArray *) allValues;
//根据key获得val
- (id) objectForKey:(NSString *)key;
//sorting….
#Program notice - NSMutableDictionary
+ (NSMutableDictionary *) dictionaryWithCapacity:(NSUInteger)capacity;
- (NSMutableDictionary *) initWithCapacity:(NSUInteger)capacity;
- (void) setObject:(id)obj forKey:(NSString *)aKey;
- (void) removeObjectForKey:(NSString *)aKey;
- (void) removeAllObjects;
#Program Notice - NSSet
NSSet *set = [NSSet setWithObjects:obj1,obj2,nil];
推荐阅读