title: Filter array of objects and sum their properties in Swift
body: <p>I would like to generate a shopping list from an array of products. 
  I have an entity "Product" in Core Data that has name (String) and amount (Int) as its properties. I am in the moment where I have an array of products with some duplicates, something like that:</p>
  
  <pre><code>var products : [Product] = [Apple, Egg, Orange, Apple, Orange, Banana, Egg, Egg]
  </code></pre>
  
  <p>How can I filter such array to get sums of amount of specific products? I would like to get as a result the list of products with their amounts like: <code>Apple: 4, Banana: 3, Egg: 7, Orange 2</code>. I know that I can make a Set from that Array to avoid duplicates, but I don't know how to sum products' amount before that.</p>