title: Looping over and combining Swift array of structs?
body: <p>I'm trying to create an array of structs (User structs below) where, if the user.name does not yet exist in the array, it appends the user -- but if the user.name is already present (&quot;Mcdonalds&quot; in the below example), then it will simply add the item.amount to the existing struct.
  In other words, the below code should create an array of 4 Users, with the User Mcdonalds item.amount totaling 23.44 + 12.33.
  I remember doing this sort of thing in JS no sweat, but I can't for the life of me figure out how to do this in Swift. Thanks for any help!</p>
  <pre><code>struct User {
      var name: String
      var amount: Double
  }
  
  var user1 = User(name: &quot;Mcdonalds&quot;, amount: 23.44)
  var user2 = User(name: &quot;Wendys&quot;, amount: 15.44)
  var user3 = User(name: &quot;Cabanos&quot;, amount: 12.22)
  var user4 = User(name: &quot;Shell Gas&quot;, amount: 23.33)
  var user5 = User(name: &quot;Mcdonalds&quot;, amount: 12.33)
  </code></pre>