title: How to create multiple buttons and action programmatically?
body: <p>I am using Swift 3.0. I am trying to generate dynamical grid of button how can I programmatically give each generated button a unique identifier</p>
  
  <pre><code>let button = UIButton(type: .system)
  @IBOutlet weak var attendanceView: UIView!
  override func viewDidLoad() {
      super.viewDidLoad()
      var xvalue = 8;
      var yvalue = 17;
      var button = UIButton();
  
      for _ in 0..&lt;5{
          for _ in 0..&lt;5{
          button = UIButton(frame: CGRect(x: xvalue, y: yvalue, width: 50 , height: 50))
          button.backgroundColor = .red()
          button.addTarget(attendanceView, action: #selector(buttonAction), for: .touchUpInside)
          self.attendanceView.addSubview(button)
          xvalue = xvalue + 72;
          }
          xvalue=8;
          yvalue = yvalue + 60;
      }
  }
  
  func buttonAction(sender: UIButton!) {
      button.backgroundColor = UIColor.green()
  }
  </code></pre>
  
  <p>I got this far but it crashes when button is clicked.</p>