title: Swiftier Swift for 'add to array, or create if not there...'
body: <p>I've noticed a common pattern in Swift is</p>
  
  <pre><code>var x:[String:[Thing]] = [:]
  </code></pre>
  
  <p>so, when you want to "add an item to one of the arrays", you can not just</p>
  
  <pre><code>x[which].append(t)
  </code></pre>
  
  <p>you have to</p>
  
  <pre><code>if x.index(forKey: which) == nil {
      x[which] = []
      }
  x[which]!.append(s!)
  </code></pre>
  
  <p>Really, is there a swiftier way to say something like</p>
  
  <pre><code>  x[index?!?!].append??(s?!)
  </code></pre>
  
  <ul>
  <li>While this is a question about style, <strong>performance seems to be a critical issue when touching arrays in Swift</strong>, due to the copy-wise nature of Swift.</li>
  </ul>
  
  <p>(Please note, obviously you can use an extension for this; it's a question about Swiftiness.)</p>