[iOS]iOS可变字典NSMutableDictionary中会遇到的坑

[iOS]iOS可变字典NSMutableDictionary中会遇到的坑_第1张图片

代码段1

    @autoreleasepool {
        
        NSMutableDictionary *mDic = [NSMutableDictionary dictionary];
        [mDic setValue:@"xiaohao" forKey:@"name"];
        [mDic setValue:@"12" forKey:@"age"];
        [mDic setValuesForKeysWithDictionary:@{@"sex":@"male"}];
        
        
        NSLog(@"%@",mDic);
    }

结果:

{
    age = 12;
    name = xiaohao;
    sex = male;
}

代码段2

    @autoreleasepool {
        
        NSMutableDictionary *mDic = [NSMutableDictionary dictionary];
        [mDic setObject:@"xiaohao" forKey:@"name"];
        [mDic setObject:@"12" forKey:@"age"];
        
        [mDic setDictionary:@{@"sex":@"male"}];
        NSLog(@"%@",mDic);
    }

结果:

{
    sex = male;
}

字典还有很多其他的坑,就不一一列举了.

你可能感兴趣的:([iOS]iOS可变字典NSMutableDictionary中会遇到的坑)