Siddharthan Asokan
Siddharthan Asokan

Reputation: 4441

Generating an NSMutableDictionary with objects of different format

How could I generate an NSMutableDictionary of the following format:

{
sitedetails = {
    currency;
    ere =         {
        price =             {
            test =                 {
                              gte = 100;
                                   };
                           };
                   };
               };
}

sitedetails is the key and currency (NSString) and ere(NSMutableDictionary with its own objects) are the objects of this NSMutableDictionary.

NSMutableDictionary *dict1 = ;[NSMutableDictionary alloc] init];
[dict1 setObject:@"currency" forKey:@"sitedetails"];
NSMutableDictionary *dict2 = ;[NSMutableDictionary alloc] init];
[dict2 setObject:ereDict forKey:@"sitedetails"];
[dict1 addEntriesFromDictionary:dict2];

This didn't let me add the string value in for dict1. Any idea where I'm going wrong?

 {
sitedetails =  {
    ere =        {
        price =     {
            test =    {
                gte = 100;
                      };
                    };
                  };
               };
 } 

Upvotes: 0

Views: 53

Answers (1)

lead_the_zeppelin
lead_the_zeppelin

Reputation: 2052

because dict1 and dict2 have the key 'sitedetails'. Keys should be unique in a dictionary. From NSMutableDictionary reference manual

If both dictionaries contain the same key, the receiving dictionary’s previous value object for that key is sent a release message, and the new value object takes its place.

Upvotes: 2

Related Questions