Reputation: 2412
There are two dictionaries like this, two dictionaries have same keys but different values.
/* dictionary 1 */
paramDict1 {
payAmount = 1000;
payType = 1;
}
/* dictionary 2 */
paramDict2 {
payAmount = 2000;
payType = 2;
}
I hope merge them to one dictionary like
paramDict {
payAmount = 1000;
payType = 1;
payAmount = 2000;
payType = 2;
}
Could you tell me how to do? Thanks.
Upvotes: 0
Views: 1856
Reputation: 17208
Even if NSDictionary preserved the order of keys, which it does not, what you're asking for is impossible because keys must be unique.
Instead, you could use an array of dictionaries:
NSArray *dicts = [NSArray arrayWithObjects: paramDict1, paramDict2, nil];
Or perhaps less idiomatically, unique keys:
paramDict {
payAmount1 = 1000;
payType1 = 1;
payAmount2 = 2000;
payType2 = 2;
}
Upvotes: 4