OC类之 Dictionary
来源:互联网 发布:菊水 清酒 知乎 编辑:程序博客网 时间:2024/06/05 00:54
@property (readonly)NSUInteger count; // 键值对数
NSDictionary :
- (NSArray *)allKeysForObject:(id)anObject; // 所有该对象的键值
+ (instancetype)dictionaryWithObject:(id)object forKey:(id <NSCopying>)key; // 键值的对象
+ (instancetype)dictionaryWithObjectsAndKeys:(id)firstObject, ... ; // 便利构造器
+ (instancetype)dictionaryWithDictionary:(NSDictionary *)dict;
+ (instancetype)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
- (instancetype)initWithObjectsAndKeys:(id)firstObject, ... ; // 初始化
- (instancetype)initWithDictionary:(NSDictionary *)otherDictionary;
- (instancetype)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
NSMutableDictionary :
- (void)removeObjectForKey:(id)aKey; // 删除
- (void)removeAllObjects;
- (void)removeObjectsForKeys:(NSArray *)keyArray;
- (void)setObject:(id)anObject forKey:(id <NSCopying>)aKey; // 没有akey创建一个, 对应对象改成anObject
- (void)setDictionary:(NSDictionary *)otherDictionary; // 设置器
数组可以嵌套字典 字典还可以嵌套数组
昨天的省市区继续
int main(int argc, const char * argv[]) { NSString *filePath = @"/Users/dllo/Desktop/OC06_省市区字典数组/OC06_省市区字典数组/area-2.txt"; NSString *mstring = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; NSArray *mArray = [mstring componentsSeparatedByString:@"\n" ]; NSCharacterSet *cSet = [NSCharacterSet characterSetWithCharactersInString:@" 0123456789"]; NSMutableArray *proArray = [NSMutableArray array]; NSMutableArray *cityArray = nil; NSMutableArray *areaArray = nil; for (NSString *s in mArray) { if (![s hasPrefix:@" "]) { NSString *s1 = [s stringByTrimmingCharactersInSet:cSet]; NSMutableDictionary *pDic = [NSMutableDictionary dictionary]; cityArray = [NSMutableArray array]; [pDic setObject:s1 forKey:@"name"]; [pDic setObject:cityArray forKey:@"cityArray"]; [proArray addObject:pDic]; } if ([s hasPrefix:@" "] && ![s hasPrefix:@" "]) { NSString *s1 = [s stringByTrimmingCharactersInSet:cSet]; areaArray = [NSMutableArray array]; NSMutableDictionary *cDic = [NSMutableDictionary dictionary]; [cDic setObject:s1 forKey:@"name"]; [cDic setObject:areaArray forKey:@"areaArray"]; [cityArray addObject:cDic]; } if ([s hasPrefix:@" "]) { NSString *s1 = [s stringByTrimmingCharactersInSet:cSet]; [areaArray addObject:s1]; } } for (NSDictionary *prodic in proArray) { NSLog(@"%@", prodic[@"name"]); NSArray* cArray = prodic[@"cityArray"]; for (NSDictionary *cityDic in cArray) { NSLog(@"%@", cityDic[@"name"]); NSArray *rArray = cityDic[@"areaArray"]; for (NSString *temp in rArray) { NSLog(@"%@", temp); } } } return 0;}
- OC类之 Dictionary
- C#之Dictionary类
- OC第五天之 Dictionary NSSet 数组排序
- OC—dictionary
- 04 OC 字典 Dictionary
- OC中的字典dictionary
- OC之OC的类
- OC类 之 NSString
- OC类 之 数组
- OC学习笔记之OC类你好
- Dictionary类
- OC 运用Dictionary & Array 实现省市区分类
- OC - Array,Dictionary,set,string方法总结
- Dictionary性能之测试
- WPF 之 Resource Dictionary
- gensim学习之Dictionary
- Dictionary之TryGetValue
- Python学习之dictionary
- android <viewStub />, <requestFocus />, <merge /> and <include />用法
- Codeforces Round #279 (Div. 2) B. Queue 模拟
- 初学者很实用:纯struts框架实现用户登陆
- android代码创建布局
- HTMLParser 学习篇上
- OC类之 Dictionary
- 自定义Dialog
- ADB端口被占用,adb server is out of date
- Flying to the Mars
- Linux下新建分区步骤
- [DLX精确覆盖] hdu 1603 A Puzzling Problem
- python scrapy 爬虫 未完待续
- The resource identified by this request is only capable of generating responses with characteristics
- 收集常用的.net开源项目