casillas
casillas

Reputation: 16793

Adding array of dictionary to array of dictionary

I had two NSDictionary elements in the finalOrderArray before addingObject. Then I added sharedData.comboItems but this object is also an array of NSDictionary.

Now,I have a mix of NSDictionary and NSArray which is difficult to handle.

Is there an easy way to add NSDictionary all together?

[finalOrderArray addObject:sharedData.comboItems];

enter image description here

Desired output in this example, finalOrderArray would have 6 dictionaries rather than having 2 dictionaries and one array of dictionary.

Upvotes: 0

Views: 68

Answers (3)

GeneCode
GeneCode

Reputation: 7588

sharedData.comboItems is an array that's why you get one array in your finalOrderArray. You need to iterate through the array, get the dictionary and add to finalOrderArray.

Like this:

for (NSDictionary *item in sharedData.comboItems) {
   [finalOrderArray addObject:item];
}

Upvotes: 0

Bilal
Bilal

Reputation: 19156

Use addObjectsFromArray method. It will add all the objects from sharedData.comboItems. Try this.

[finalOrderArray addObjectsFromArray: sharedData.comboItems];

Upvotes: 1

Puneet Sharma
Puneet Sharma

Reputation: 9484

Use addObjectsFromArray: method.

Adds the objects contained in another given array to the end of the receiving array’s content.

Here is the link to NSMutableArray and all its methods.

Upvotes: 3

Related Questions