Reputation: 812
I am looking to merge dictionaries in response to the user requesting more data from a server call.
I see this method is one available to me:
- (void)addEntriesFromDictionary:(NSDictionary *)otherDictionary
Which states this:
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.
However for example on the first call my dictionary will have the keys 0, 1, 2, 3 as strings. Dont ask why this is the data I have to work with!
Then on another call for say the next 4 entries rather than getting string keys 4, 5, 6, 7 I get....0, 1, 2, 3!
So if I use the method above the original entries will always be overwritten.
Is there a way to merge such data so I get 1, 2, 3, 4, 5, 6, 7 etc?
Am I looking at some ugly form of enumeration?
Upvotes: 1
Views: 8036
Reputation: 5050
If all of your keys are sequential integers, you should be using arrays instead (or convert to them if you can't change the source format). arrayByAddingObjectsFromArray:
will join them together after conversion, or addObjectsFromArray:
if mutable.
Upvotes: 2