开发者

merging two dictionaries

开发者 https://www.devze.com 2023-03-13 02:17 出处:网络
I am looking to merge dictionaries in response to the use开发者_StackOverflow社区r requesting more data from a server call.

I am looking to merge dictionaries in response to the use开发者_StackOverflow社区r 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消