OC -- NSMutableDictionary

作者: J_coco | 来源:发表于2016-01-23 16:05 被阅读0次
    /*___________________________可变数组NSMutableDictionary__________________________________*/
    
    //1.创建
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    NSMutableDictionary *dic1 = [NSMutableDictionary dictionary];
    NSMutableDictionary *dic2 = [[NSMutableDictionary alloc]initWithCapacity:5];
    NSMutableDictionary *dic3 = [NSMutableDictiona dictionaryWithCapacity:5];
    
    //2.方法
    NSArray *array = @[@"arr1",@"arr2"];
    //1.增&改:添加[键值对]
    
    /*
      1) 判断字典中是否有该键,如果没有则添加新的键值对
                                            如果有则替换键原来所对应的对象
    */
    
    [dic setObject:array forKey:@"0"];
    [dic setObject:array forKey:@"1"];
    [dic setObject:array forKey:@"2"];
    [dic setObject:array forKey:@"3"];
    
    NSLog(@"%@",dic);
    
    
    //2.删:移除 [键值对]
      //移除全部
    [dic removeAllObjects];
    
      //移除一个
    [dic removeObjectsForKeys:@[@"1",@"2"]];
    
    //移除多个
    [dic removeObjectsForKeys:@[@"1",@"2"]];
    
    NSLog(@"%@",dic)
    
    
    

    相关文章

      网友评论

        本文标题:OC -- NSMutableDictionary

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