title: Swift computed property to return copy of underlying array
body: <p>I have a model class written in Objective-C that I'm converting to Swift. It contains an <code>NSMutableArray</code> internally, but the method signature for the getter, as well as the actual return value, are <code>NSArray</code>. When called, it creates an <em>immutable copy</em> to return.</p>
  
  <p>Essentially, I want callers to be able to iterate/inspect the container, but not modify it. I have this test snippet:</p>
  
  <pre><code>class Container {
      internal var myItems = [String]()
  
      func sayHello() {
          "I have: \(myItems)"
      }
  }
  
  let cont = Container()
  
  cont.myItems.append("Neat") // ["Neat"]
  
  cont.sayHello() // This causes sayHello() to print: "I have: [Neat]"
  
  var isThisACopy = cont.myItems
  
  isThisACopy.append("Huh") // ["Neat", "Huh"]
  
  cont.sayHello() // This ALSO causes sayHello() to print: "I have: [Neat]"
  </code></pre>
  
  <p>I've been trying to find a way to override the getter for <code>myItems</code> so that it returns an immutable copy, but can't seem to determine how.</p>
  
  <p><strong>Attempt #1</strong></p>
  
  <p>This produces a compiler error: <code>Function produces expected type '_ArrayBuffer&lt;(String)&gt;'; did you mean to call it with '()'?</code></p>
  
  <pre><code>internal var myItems = [String]() {
      var copy = [String]()
      for item in ... { // What to use in the ...?
          copy.append(item)
      }
      return copy
  }
  </code></pre>
  
  <p><strong>Attempt #2</strong></p>
  
  <p>This also produces a compiler error, because I'm (understandably) redefining the generated getter <code>Invalid redeclaration of 'myItems()'</code>:</p>
  
  <pre><code>internal func myItems() -&gt; [String] {
      var copy = [String]()
      for item in myItems {
          copy.append(item)
      }
      return copy
  }
  </code></pre>