NSDictionary * dic =
@{@"key":@"value",
@"key1":@"value1",
@"key2":@"value2",
@"key3":@"value3"};
NSLog(@"%@",dic);
//1.先取出字典中的keys,然后對(duì)使用數(shù)組的方式對(duì)key進(jìn)行遍歷
NSArray * array = [dic allKeys];
for (NSString * key in array) {
//? ? ? ? ? ? NSString * value2 = [dic objectForKey:key];
NSString * value = dic[key];
NSLog(@"%@",value);
}
//2.快速遍歷字典
//key1不能代表鍵值對(duì) 代表的是key
for (NSString * key1 in dic) {
NSString * value2 = dic[key1];
NSLog(@"%@",value2);
}
//枚舉器
//keyEnumerator //枚舉的是key
//objectEnumerator //枚舉的是value
NSEnumerator * e = [dic keyEnumerator];
NSString * key;
//代表的是key
while ((key = [e nextObject])!=nil) {
NSString * value = dic[key];
NSLog(@"%@",value);
}