NSMutableArray *dicToArray = [NSMutableArray array];
NSMutableDictionary *arrayToDic = [NSMutableDictionary dictionary];
NSDictionary *dic = @{@"1":@"one",@"2":@"two",@"3":@"three"};
//字典转数组
[dic enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
[dicToArray addObject:[NSString stringWithFormat:@"%@:%@",key,obj]];
}];
NSLog(@"dicToArray====%@",dicToArray);
//数组转字典
[dicToArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"obj===%@===idx===%lu",obj,(unsigned long)idx);
NSArray *array = [obj componentsSeparatedByString:@":"];//分割字符串
[arrayToDic setObject:array[1] forKey:array[0]];
}];
NSLog(@"arrayToDic====%@",arrayToDic);
dicToArray====(
"1:one",
"2:two",
"3:three"
)
arrayToDic===={
1 = one;
2 = two;
3 = three;
}