Identify and count array duplicates <p>I have the following array:</p> <pre><code>var newOrderItems = [Order]() </code></pre> <p>that holds Order type elements:</p> <pre><code>let order = Order(item: itemName, quantity: 1) newOrderItems.append(order!) </code></pre> <p>At some point newOrderItems holds:</p> <pre><code>[ Order("item1", 1), Order("item1", 1), Order("item2", 1), Order("item2", 1), Order("item3", 1), Order("item1", 1) ] </code></pre> <p>I need to identify and count duplicate Order array elements so that I form a string message such as: </p> <p>"You have ordered 3 x item1, 2 x item2, 1 x item3".</p> <p>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 <code>NSCountedSet</code>) for something that I expect to be trivial.</p>