OC -- NSMutableDictionary
2016-01-23 本文已影响0人
J_coco
/*___________________________可变数组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)