I have the following array:
var newOrderItems = [Order]()
that holds Order type elements:
let order = Order(item: itemName, quantity: 1)
newOrderItems.append(order!)
At some point newOrderItems holds:
[
Order("item1", 1),
Order("item1", 1),
Order("item2", 1),
Order("item2", 1),
Order("item3", 1),
Order("item1", 1)
]
I need to identify and count duplicate Order array elements so that I form a string message such as:
"You have ordered 3 x item1, 2 x item2, 1 x item3".
Is there a simple way for this? My solution(s) either add way too much overhead (i.e nested loops), or too much complexity (i.e. unique NSCountedSet) for something that I expect to be trivial.