
代码段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;
}
字典还有很多其他的坑,就不一一列举了.
网友评论
Instance Method
setDictionary(_:)
Sets the contents of the receiving dictionary to entries in a given dictionary.
Discussion
All entries are removed from the receiving dictionary (with removeAllObjects()), then each entry from otherDictionary added into the receiving dictionary.