title: Swift Accessing UIButton Tags
body: <p>I created multiple buttons with unique tags and added the buttons to the UIView of my project. I want to re-access them so I can add the buttons into a views dictionary for autolayout.</p>
  
  <pre><code>func createButtons() {
      for index in 0...10 {
          var button = UIButton.buttonWithType(UIButtonType.System) as UIButton
          button.tag = index
          self.view.addSubview(button)
   }
  </code></pre>
  
  <p>Code to create a views dictionary for autolayout purposes.</p>
  
  <pre><code>func createDictionary() {
      var mbd : [String:UIButton]! = [:]
  
      for index in 0...10 {
          let tmpButton = self.view.viewWithTag(index) as? UIButton
          mbd["button" + String(index)] = tmpButton
      }
      return mbd
  }
  </code></pre>
  
  <p>However, I don't think the above code is creating any dictionary and I am not sure why. If I shift the code which I append to the dictionary in the first <code>for loop</code> then everything works. But I am trying to learn to use the <code>viewWithTag</code> method as I will need it frequently.</p>
  
  <p>Any guidance is appreciated.</p>