美文网首页iOS9开发技术
[iOS]iOS可变字典NSMutableDictionary中

[iOS]iOS可变字典NSMutableDictionary中

作者: 肖浩呗 | 来源:发表于2016-09-01 15:40 被阅读130次

代码段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;
}

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

相关文章

网友评论

  • 5b489f67a2b3:这个不是坑把,文档的用法就是这样写的
    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.
    郑大爷:真相了,不看文档总是觉得苹果哪里都是坑,其实是自己无*

本文标题:[iOS]iOS可变字典NSMutableDictionary中

本文链接:https://www.haomeiwen.com/subject/ieacettx.html