I have one array that is pre-filled with dictionaries with each dictionary consisting of two keys.
{
name = object1;
quantity = 5;
},
{
name = object2;
quantity = 2;
}
I want to be able to add more objects and combine any duplicate dictionaries. So for example, if I added 5 of object one and 3 of object 2, this would be the result.
{
name = object1;
quantity = 10;
},
{
name = object2;
quantity = 5;
}
My ultimate goal is to be able to display the quantity next to the item in a table view. What is the best way to accomplish this?
If you really want to iterate through your existing structure then you could do something like:
I assumed you stored the quantity as an NSString, you may have used something else like NSNumber.
I think a better idea is create your own class with two properties, a name and a quantity. Then hold one array of those objects and iterate through that.