for in遍历字典时只能先得到value ,再通过value取对应的key
enumerateKeysAndObjectsUsingBlock 可以同时遍历出key和value
通过value取key的方法
- (void)setEnumDictionary
{
NSDictionary *dic = [NSDictionary dictionary];
dic = @{
@"1":@"a",
@"2":@"b",
@"3":@"c",
@"4":@"d",
@"5":@"e",
@"6":@"f",
@"7":@"g",
@"8":@"h",
@"9":@"i",
@"10":@"j",
@"11":@"k",
@"12":@"L",
};
[dic enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
if ([@"d" isEqualToString:obj]) {
NSLog(@" = %@",key);
*stop = YES;
}
}];
}