NSDictionary *dic1=[NSDictionary dictionaryWithObjectsAndKeys: @"1",@"a",
@"2",@"b", @"3",@"c", @"2",@"d", nil];
NSLog(@"%zi",[dic1 count]); //结果:4
NSLog(@"%@",[dic1 valueForKey:@"b"]);//根据键取得值,结果:2
NSLog(@"%@",dic1[@"b"]);//还可以这样读取,结果:2
NSLog(@"%@,%@",[dic1 allKeys],[dic1 allValues]);
NSDictionary *dic1=[NSDictionary dictionaryWithObjectsAndKeys: @"1",@"a",
@"2",@"b", @"3",@"c", @"2",@"d", nil];
NSLog(@"%zi",[dic1 count]); //结果:4
NSLog(@"%@",[dic1 valueForKey:@"b"]);//根据键取得值,结果:2
NSLog(@"%@",dic1[@"b"]);//还可以这样读取,结果:2
NSLog(@"%@,%@",[dic1 allKeys],[dic1 allValues]);
NSLog(@"%@",[dic1 objectsForKeys:[NSArray arrayWithObjects:@"a",@"b",@"e","r", nil]notFoundMarker:@"not found"]);//后面一个参数notFoundMarker是如果找不到对应的key用
NSMutableDictionary *dic=[NSMutableDictionary
dictionaryWithObjectsAndKeys:@"1",@"a", @"2",@"b", @"3",@"c", @"2",@"d",nil];
//[dic removeObjectForKey:@"b"];
//NSLog(@"%@",dic);
/*结果:
{
a = 1;
c = 3;
d = 2; }
*/
//[dic addEntriesFromDictionary:@{@"e":@"7",@"f":@"6"}];
//NSLog(@"%@",dic);
/*结果:
{
a = 1;
c = 3; d = 2; e = 7; f = 6;
} */
//setValue:value forkey:key 如果key存在,修改value;否则添加
[dic setValue:@"5" forKey:@"a"];
[dic setValue:@"5" forKey:@"f"];
NSLog(@"%@",dic);