如何添加到现有的Nsmutabledictionary?

时间:2013-03-20 13:06:29

标签: iphone ios nsmutabledictionary

大家好,我有一个可变的Nsdcitionary。我有一个函数,它使用这个dict = [json mutableCopy];设置Nsdcitionary内容。现在我想重新调用该函数,但我需要保留旧值。怎么做?

2 个答案:

答案 0 :(得分:0)

我想这可以帮助

[dict1 addEntriesFromDictionary:dict2];

答案 1 :(得分:0)

试试这个

NSMutableDictionary *dict1=[[NSMutableDictionary alloc]init];
[dict1 setObject:@"ravi" forKey:@"Name"];

NSMutableDictionary *dict2=[[NSMutableDictionary alloc]init];
[dict2 setObject:@"22" forKey:@"Age"];

[dict1 addEntriesFromDictionary:dict2];

NSLog(@"%@",dict1);
//it will print 

//    Age = 22;
 //   Name = ravi;