title: How do you create an immutable array in Swift?
body: <p>How do I create an immutable array in Swift?</p>
  
  <p>A superficial reading of the docs would suggest you can just do </p>
  
  <pre><code>let myArray = [1,2,3]
  </code></pre>
  
  <p>But sadly this actually produces a mutable, fixed-size array. This mutability creates the usual puzzles with unsuspected aliasing and functions mutating their arguments:</p>
  
  <pre><code>let outterArray = [myArray, myArray]
  outterArray[0][0] = 2000
  outterArray //=&gt; [[2000,2,3],[2000,2,3]]   surprise!
  
  func notReallyPure(arr:Int[]) -&gt; () { arr[0] = 3000 }
  notReallyPure(myArray)
  myArray // =&gt; [3000,2,3]
  </code></pre>
  
  <p>Not much better than C.</p>
  
  <p>If I want immutability, is the best option really to wrap it in an <code>NSArray</code> like so:</p>
  
  <pre><code>let immutableArray = NSArray(myArray: [1,2,3])
  </code></pre>
  
  <p>That seems nuts. What am I missing here?</p>
  
  <p><strong>UPDATE (2015-07-26):</strong></p>
  
  <p>This question dates from the very early days of Swift. Swift has since then been updated so that immutable arrays are actually immutable, as answers below indicate.</p>