title: Swift: Reference ("pointer") to collection
body: <p>this is probably a very basic/stupid question: how do I get a reference to a collection in Swift, such that a change to that reference affects the original and vice versa? So if for instance I have the following code: </p>
  
  <pre><code>var a1 = [Int]()
  var a2 = a1
  a1.append(1)
  print(a2)
  </code></pre>
  
  <p>Can I get a "reference" (or whatever name it would have in Swift) to <code>a1</code> such that when I change <code>a1</code>, <code>a2</code> reflects the same change, and it ends up displaying "[1]" instead of "[]"?</p>
  
  <p>I guess this has to do with collections being primary types, and thus not behaving like other objects, but then I'm at a loss as to how I can play around with collections without them being duplicated all the time. </p>
  
  <p>More specifically, when working with a <code>Dictionary&lt;String, Dictionary&lt;String, Int&gt;&gt;</code>, what's the best way to update the contents of the nested <code>Dictionary</code> while minimizing the number of lookups? The following approach used to work in Java but I guess it's different with Swift: </p>
  
  <pre><code>var dict = Dictionary&lt;String, Dictionary&lt;String, Int&gt;&gt;()
  var d = dict["a"]
  if d == nil {
      d = Dictionary()
      dict["a"] = d
  }
  d!["b"] = 1
  print("\(dict["a"]!["b"])")
  </code></pre>
  
  <p>prints "nil"</p>
  
  <p>(Note: if possible, I'd like to avoid multiple <code>dict["a"]!["b"]</code> lookups)</p>
  
  <p>Thanks!</p>