Appending NSDictionary to other NSDictionary

Objective CIosUitableviewNsdictionary

Objective C Problem Overview


I have one NSDictionary and it loads up UITableView. If a user scrolls more and more, I call API and pull new data. This data is again in the form of an NSDictionary. Is it possible to add the new NSDictionary to the existing one?

Objective C Solutions


Solution 1 - Objective C

You looking for this guy:

[NSMutableDictionary addEntriesFromDictionary:]

Make sure your UITableView dictionary is an NSMutableDictionary!

Check it here

Solution 2 - Objective C

Use NSMutableDictionary addEntriesFromDictionary to add the two dictionaries to a new mutable dictionary. You can then create an NSDictionary from the mutable one, but it's not usually necessary to have a dictionary non-mutable.

Solution 3 - Objective C

Is your NSDictionary full of other NSDictionaries? It sounds like you would need an NSMutableArray that you could add NSDictionaries to at the end. Assuming you can control the flow of data coming in and wouldn't run the risk of duplicates in your array, you could certainly append the data.

NSMutableArray *array = [[NSMutableArray alloc] init];
arrayCount = [array count]; // check the item count
[array addObject:dictToAppend];

Without seeing how you are implementing it, I can't provide more detailed code examples. Appending items is easy to do, but know it can only be done with mutable versions of Arrays or Dictionaries. Hope this helps a little.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionslonkarView Question on Stackoverflow
Solution 1 - Objective CMGAView Answer on Stackoverflow
Solution 2 - Objective CHot LicksView Answer on Stackoverflow
Solution 3 - Objective CBill BurgessView Answer on Stackoverflow