title: Trigger an action when an user clicks on a cell in swift
body: <p>I'm creating an app using Swift.
  I have an <code>UITableView</code> that I populate with some data from a database. When user clicks on a cell, I would like to trigger an action.</p>
  
  <p>What I have done : </p>
  
  <pre><code>var array: [String] = ["example"]
  
  
      func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return array.count
      }
  
  
  
      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
          var cell = UITableViewCell(style :UITableViewCellStyle.Default, reuseIdentifier: "cell")
          cell.textLabel.text = array[indexPath.row]
          cell.tag = indexPath.row
          cell.targetForAction("getAction:", withSender: self)
          return cell
      }
  
      func getAction(sender:UITableViewCell)-&gt;Void {
          if(sender.tag == 0) {
              println("it worked")
          }
      }
  </code></pre>
  
  <p>I tried to adapt a solution from an another post but I did it definitely wrong. Thank you in advance</p>