NSDictionary * dic =
@{@"key":@"value",
@"key1":@"value1",
@"key2":@"value2",
@"key3":@"value3"};
NSLog(@"%@",dic);
//1.先取出字典中的keys,然后对使用数组的方式对key进行遍历
NSArray * array = [dic allKeys];
for (NSString * key in array) {
// NSString * value2 = [dic objectForKey:key];
NSString * value = dic[key];
NSLog(@"%@",value);
}
//2.快速遍历字典
//key1不能代表键值对 代表的是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);
}