Day.01.19 可变‘字典’

#import 

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        /*_______可变数组 NSMutableDictionary________________________________________________________*/
        
        //1⃣️创建
        
        NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
        
        NSMutableDictionary *dic1 = [NSMutableDictionary dictionary];
        
        NSLog(@"%@",dic1);
        
        NSMutableDictionary *dic2 = [[NSMutableDictionary alloc]initWithCapacity:5];
        
        NSLog(@"%@",dic2);
        
        NSMutableDictionary *dic3 = [NSMutableDictionary dictionaryWithCapacity:5];
        
        NSLog(@"%@",dic3);
        
        //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 removeObjectForKey:@"0"];
        
            //移除多个
        [dic removeObjectsForKeys:@[@"1",@"2"]];
        
        NSLog(@"%@",dic);
        
    }
    return 0;
}

2016-01-19 19:29:36.877 07NSMutableDictionary[1385:201302] {
}
2016-01-19 19:29:36.879 07NSMutableDictionary[1385:201302] {
}
2016-01-19 19:29:36.879 07NSMutableDictionary[1385:201302] {
}
2016-01-19 19:29:36.879 07NSMutableDictionary[1385:201302] {
    0 =     (
        arr1,
        arr2
    );
    1 =     (
        arr1,
        arr2
    );
    2 =     (
        arr1,
        arr2
    );
    3 =     (
        arr1,
        arr2
    );
}
2016-01-19 19:29:36.879 07NSMutableDictionary[1385:201302] {
    3 =     (
        arr1,
        arr2
    );
}
Program ended with exit code: 0

你可能感兴趣的:(Day.01.19 可变‘字典’)