Establezca restricciones a través del código a un elemento de Storyboard con rápido iOS8

Tengo un ViewController con una tableView. Lo configuré en el Storyboard. ¿Hay alguna manera de establecer las restricciones para tableView mediante programación? Intenté establecer un IBOutlet desde mi tableView en ViewController y le agregué restricciones. Pero eso no funcionó.

Este es mi ViewController

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

@IBOutlet weak var tableView: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()

    addTableViewConstraints()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func addTableViewConstraints() {

    tableView.setTranslatesAutoresizingMaskIntoConstraints(false)

    var topConstraint = NSLayoutConstraint(item: self.tableView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Top, multiplier: 1.0, constant: 20)
    var leadingContraint = NSLayoutConstraint(item: self.tableView, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Leading, multiplier: 1.0, constant: 0)
    var trailingConstraint = NSLayoutConstraint(item: self.tableView, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Trailing, multiplier: 1.0, constant: 0)
    var bottomConstraint = NSLayoutConstraint(item: self.tableView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 0)

    self.view.addConstraints([topConstraint, leadingContraint, trailingConstraint, bottomConstraint])

}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 5
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
    cell.textLabel?.text = "Cell"
    return cell
}
}

¿O tengo que hacer que mi tabla vea también el código?

¡Gracias!

Respuestas a la pregunta(0)

Su respuesta a la pregunta