标签:
遍历第一种方法
NSDictionary *dict1 = @{@"name":@"纠结伦",@"age":@"36",@"sex":@"男"};
for (NSString *key in dict1) {
NSLog(@"%@ = %@",key,[dict1 objectForKey:key]);
}
第二种方法 block 方法
[dict1 enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
NSLog(@"%@ = %@",key,obj);
}];
得到词典的数量
unsigned long count =[dict1 count];
NSLog(@"%lu",count);
得到词典的所有的key值
NSEnumerator *enumerKey = [dict1 keyEnumerator];
for (NSObject *object in enumerkey) {
NSLog(@"遍历key的值:%@",object);
}
得到词典所有的value值
NSEnumerator *enumeValue = [dict1 objectEnumerator];
for (NSObject *object in enumeValue) {
NSLog(@"遍历value的值:%@",object);
}
通过KEY找到value
if ([dict1 objectForKey:@"name"] != nil) {
NSLog(@"%@",[dict1 objectForKey:@"name"]);
}
标签:
原文地址:http://www.cnblogs.com/xggz/p/4774712.html