Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy NSMutableDictionary values into the another NSMutableDictionary in iPhone?

I want to copy a NSMUtableDictionary values into the another NSMutableDictioary. How can i do that?

Here my code is,

 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.
}

I want to access the tempDictionary values to the person class. SO how can i copy from feedDictionary to the tempDictionary. Please help me out.

Thanks.

like image 751
Pugalmuni Avatar asked Nov 29 '22 04:11

Pugalmuni


2 Answers

How about this?

tempDictionary = [[NSMutableDictionary alloc]initWithDictionary:feedDictionary];

Cheers

like image 123
Fran Sevillano Avatar answered Dec 09 '22 17:12

Fran Sevillano


[feedDictionary mutableCopy];

This will copy all entries in the dictionary, but it will not copy custom objects unless you implement the NSCopying protocol.

like image 43
nonamelive Avatar answered Dec 09 '22 17:12

nonamelive