title: How can I programmatically set dataSource of UITableView?
body: <p>I am having a strange problem. I am trying to assign a dataSource to a table programatically.</p>
  
  <p>I have created a <code>UITableView</code> and an IBOutlet for it in my ViewController using the Interface Builder. I have created a class that implements <code>UITableViewDataSource</code>. I set the <code>dataSource</code> of my table to be an instance of the dataSource. Everything compiles and runs fine, until the line that sets the dataSource is executed in runtime.</p>
  
  <p>The error is <code>Thread 1: EXC_BAD_ACCESS (code=EXC_i386_GPFLT)</code> and the <code>class AppDelegate</code> definition line is highlighted.</p>
  
  <pre><code>class ViewController: UIViewController {
  
      @IBOutlet weak var table: UITableView!
  
      override func viewDidLoad() {
          let ds = MyData()
          table.dataSource = ds // &lt;---- Runtime error
          table.reloadData()
          super.viewDidLoad()
      }
      // ... other methods
  }
  
  
  class MyData: NSObject, UITableViewDataSource {
      func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -&gt; Int {
          return 5
      }
      func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -&gt; UITableViewCell! {
          let cell = UITableViewCell()
          cell.textLabel.text = "a row"
          return cell
      }
  }
  </code></pre>
  
  <p>Any ideas why I am getting this runtime error? I am using XCode 6 beta 4 with Swift.</p>