title: Setting NSTableView cell text
body: <p>I have a NSTableView that I want to populate with 20 cells, each of them will say "Test". I'm fluent with UITableView's but not so much with NSTableViews, so I went hunting online to figure this out. Oh, how confused that made me! I understand that I need to use the <code>numberOfRowsInTableView</code> function, but how do I set the text of the cell? Each source I find seems to do everything in a different way. For instance, <a href="http://www.raywenderlich.com/87002/getting-started-with-os-x-and-swift-tutorial-part-1" rel="nofollow noreferrer">this</a> site uses:</p>
  
  <pre><code>func tableView(tableView: NSTableView!, viewForTableColumn tableColumn: NSTableColumn!, row: Int) -&gt; NSView! {
  // 1
  var cellView: NSTableCellView = tableView.makeViewWithIdentifier(tableColumn.identifier, owner: self) as NSTableCellView
  
  // 2
  if tableColumn.identifier == "BugColumn" {
    // 3
    let bugDoc = self.bugs[row]
    cellView.imageView!.image = bugDoc.thumbImage
    cellView.textField!.stringValue = bugDoc.data.title
    return cellView
  }
  
  return cellView
  </code></pre>
  
  <p>}</p>
  
  <p>I tried that but I got an error - the code found nil while unwrapping an optional. Then I tried what I found <a href="https://stackoverflow.com/questions/27692177/cell-based-nstableview-behaves-incorrectly">here</a>:</p>
  
  <pre><code>func tableView(tableView: NSTableView, dataCellForTableColumn tableColumn: NSTableColumn?, row: Int) -&gt; NSCell? {
  if tableColumn == nil { return nil }
  if tableColumn!.identifier != "right" { return nil }
  let cell = NSPopUpButtonCell()
  cell.bordered = false
  cell.menu!.addItemWithTitle("one", action: nil, keyEquivalent: "")
  cell.menu!.addItemWithTitle("two", action: nil, keyEquivalent: "")
  cell.menu!.addItemWithTitle("three", action: nil, keyEquivalent: "")
  cell.selectItemAtIndex(1) // &lt;--- obviously ignored ?!
  return cell
  </code></pre>
  
  <p>}</p>
  
  <p>So my question is, how do I set the cell text? How do the two examples I've inserted above differ in what they do? Please, make some sense of this - cause I sure can't!</p>
  
  <p>-Thanks,
  A confused CodeIt</p>
  
  <p>P.S.
  I've looked at several other sources except the two I named above. I'm just plain confused.. </p>
  
  <p><strong>Edit:</strong>
  The found nil while unwrapping an Optional error I mentioned in the first example is found on this line:</p>
  
  <pre><code>var cellView: NSTableCellView = tableView.makeViewWithIdentifier(tableColumn.identifier, owner: self) as NSTableCellView
  </code></pre>