iOS 根据value取到 Dictionary 对应的key值

快速遍历取出value 对应字典中的 key 值


 NSString *brithdayStrDefult;//上页面传过来的生日值

 NSDictionary * brithdayDic = @{@"0":@"60后",@"1":@"70后",@"2":@"80后",@"3":@"90后",@"4":@"00后"};

    //遍历取值
    if (brithdayStrDefult.length>0) {
        [brithdayDic enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {

            NSLog(@"key = %@ and obj = %@", key, obj);

            if ([obj isEqualToString: brithdayStrDefult]) {
                self.selectIndex = [key integerValue];


                NSLog(@"----------%ld",self.selectIndex);

            }

        }];

你可能感兴趣的:(ios-基础)