title: Unexpectedly found nil while unwrapping an Optional value swift
body: <p>I'm getting an error message "Unexpectedly found <code>nil</code> while unwrapping an <code>Optional</code>" from Swift, with the below class. The error occurs on the line:</p>
  
  <pre><code>(cell.contentView.viewWithTag(1) as UILabel).text = object["firstName"] as? String
  </code></pre>
  
  <p>I have a custom cell class with 2 UILabels tagged 1 and 2, the outlets are set</p>
  
  <pre><code>    import UIKit
      import Foundation
  
      class dictionaryTableViewController: UIViewController,       UITableViewDelegate, UITableViewDataSource{
  
      var objects = NSMutableArray()
      var dataArray = [["firstName":"Debasis","lastName":"Das","email":"debasis_das@knowstack.com"],["firstName":"John","lastName":"Doe","email":"jdoe@knowstack.com"],["firstName":"Jane","lastName":"Doe","email":"janedoe@knowstack.com"],["firstName":"Mary","lastName":"Jane","email":"mjane@knowstack.com"]]
  
      @IBOutlet
      var tableView: UITableView!
  
      var items: [String] = ["We", "Heart", "Swift"]
  
      override func viewDidLoad() {
          super.viewDidLoad()
          self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "MyCell")
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
      }
  
  
      func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return dataArray.count;//self.items.count;
      }
  
      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
          //var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
          //cell.textLabel?.text = self.items[indexPath.row]
          //return cell
          let cell = tableView.dequeueReusableCellWithIdentifier("MyCell", forIndexPath: indexPath) as UITableViewCell
          let object = dataArray[indexPath.row] as NSDictionary
          (cell.contentView.viewWithTag(1) as UILabel).text = object["firstName"] as? String
          (cell.contentView.viewWithTag(2) as UILabel).text = object["lastName"] as? String
          return cell
      }
  
      func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
  
          println("You selected cell #\(indexPath.row)!")
  
      }
  
  }
  </code></pre>