NSMutableDictionary *dic=[[NSMutableDictionary alloc] init];
[dic setValue:@"abc" forKey:@"1"];
[dic setValue:@"你好" forKey:@"2"];
[dic setValue:@"哈哈" forKey:@"3"];
NSArray *arr=[dic allKeys];
NSString *name=@"你好";
for (NSString *key in arr)
{
if ( [name isEqualToString:[dic objectForKey:key] ] )
{
NSLog(@"找到了 %@ 对应的key 值是 :%@",name,key);
}
}
重复(value)
NSMutableDictionary *dic=[[NSMutableDictionary alloc] init];
NSMutableArray *arrkey=[[NSMutableArray alloc] init];
[dic setValue:@"abc" forKey:@"1"];
[dic setValue:@"你好" forKey:@"2"];
[dic setValue:@"哈哈" forKey:@"3"];
[dic setValue:@"哈哈" forKey:@"4"];
[dic setValue:@"哈哈" forKey:@"5"];
[dic setValue:@"哈哈" forKey:@"6"];
[dic setValue:@"456" forKey:@"7"];
[dic setValue:@"凤姐" forKey:@"8"];
NSArray *arr=[dic allKeys];
NSString *name=@"哈哈";
for (NSString *key in arr)
{
if ( [name isEqualToString:[dic objectForKey:key] ] )
{
[arrkey addObject:key];
}
}
NSLog(@"name= 哈哈 的id 如下:%@",arrkey);
[arrkey release];
[arr release];
[dic release];