title: Stack implementation in Swift
body: <p>I'm new to Swift and iOS programming.</p>
  
  <p>I'm trying to test out a simple algorithm and need an array of Stacks. Don't have to be anything fancy (Stacks of Ints will do).</p>
  
  <p>I got the Stack implementation from <a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Generics.html#//apple_ref/doc/uid/TP40014097-CH26-XID_283" rel="nofollow noreferrer">The Swift Programming Language documentation</a>:</p>
  
  <pre><code>struct IntStack {
      var items = [Int]()
      mutating func push(item: Int) {
          items.append(item)
      }
      mutating func pop() -&gt; Int {
          return items.removeLast()
      }
      mutating func count() -&gt; Int {
          return items.count
      }
      mutating func show() {
          println(items)
      }
  }
  </code></pre>
  
  <p>The count and show functions are my contribution. But when I try to declare an array of Stacks I get an error...</p>
  
  <pre><code>var lines = IntStack()[5]
  </code></pre>
  
  <p>"IntStack" does not have a member named subscript</p>
  
  <p>I'm guessing it has something to do with Optionals but can figure out what it is.</p>
  
  <p>Any help?</p>