如何将NSMutableDictionary值复制到iPhone中的另一个NSMutableDictionary?

Pug*_*gal 4 iphone nsmutabledictionary

我想将NSMUtableDictionary值复制到另一个NSMutableDictioary中.我怎样才能做到这一点?

我的代码是,

 PersonClass.h file:

 NSMutableDictionary *tempDictionary;
 @property (nonatomic, retain) NSMutableDictionary *tempDictionary;

 PersonClass.m
 @synthesize tempDictionary; 

 tempDictionary = [[NSMutableDictionary alloc] init];

-(PersonClass *) initWithPerson:(NSMutableDictionary *) feedDictionary
{
     // get all the values in feedDictionary.

     //Now i want copy of the details from feedDictionary into the tempDictionary

           tempDictionary = feedDictionary; // Doesn't copy.
}
Run Code Online (Sandbox Code Playgroud)

我想访问person类的tempDictionary值.那我如何从feedDictionary复制到tempDictionary.请帮帮我.

谢谢.

Fra*_*ano 19

这个怎么样?

tempDictionary = [[NSMutableDictionary alloc]initWithDictionary:feedDictionary];
Run Code Online (Sandbox Code Playgroud)

干杯


non*_*ive 5

[feedDictionary mutableCopy];
Run Code Online (Sandbox Code Playgroud)

这将复制字典中的所有条目,但除非您实施NSCopying协议,否则它不会复制自定义对象.