title: UITableViewCell in Swift
body: <p>This is a sample code with <code>UITableViewController</code> and <code>CoreData</code>. Main file <code>MainTableViewController.swift</code>:</p>
  
  <pre><code>import UIKit
  import CoreData
  
  class MainTableViewController: UITableViewController {
  
  var results:AddrBook[]=[]
  
  init(style: UITableViewStyle) {
      super.init(style: style)
  }
  
  init(coder aDecoder: NSCoder!) {
      super.init(coder: aDecoder)
  }
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
  }
  
  override func viewDidAppear(animated: Bool) {
      let request = NSFetchRequest(entityName: "Person")
      request.returnsObjectsAsFaults = false
      let appDelegate:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
      let context:NSManagedObjectContext = appDelegate.managedObjectContext
      results  = context.executeFetchRequest(request, error: nil) as AddrBook[]
      self.tableView.reloadData()
  }
  
  override func numberOfSectionsInTableView(tableView: UITableView?) -&gt; Int {
      return 1
  }
  
  override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -&gt; Int {
      return results.count
  }
  
  override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell! {
      var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as? UITableViewCell
  
      if !cell {
          cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
      }
  
      cell!.textLabel.text = results[indexPath.row].lastname + " " + results[indexPath.row].firstname
  
      return cell
  }
  
  override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject?) {
  
      var indexPath = self.tableView.indexPathForSelectedRow()
      let destViewController:DetailViewController! = segue.destinationViewController as DetailViewController
  
      if segue.identifier == "editPerson" {
          destViewController.receivedPerson = results
          destViewController.indexPath = indexPath
      }
  }
  }
  </code></pre>
  
  <p>If in <code>cellForRowAtIndexPath</code> I use this:</p>
  
  <pre><code>cell!.textLabel.text = results[indexPath.row].lastname + " " + results[indexPath.row].firstname
  </code></pre>
  
  <p>then all is good. But if I use this:</p>
  
  <pre><code>cell!.textLabel.text = results[indexPath.row].lastname
  cell!.detailTextLabel.text = results[indexPath.row].firstname
  </code></pre>
  
  <p>I see error: <code>Can't unwrap Optional.None</code></p>
  
  <p>What's wrong? Help, please.</p>
  
  <p>Just in case the codes of other classes</p>
  
  <p>Class <code>UIViewController</code> for add and edit records (<code>DetailViewController.swift</code>):</p>
  
  <pre><code>import UIKit
  import CoreData
  
  class DetailViewController: UIViewController {
  
  @IBOutlet var currentOperation : UILabel = nil
  @IBOutlet var firstnameField : UITextField = nil
  @IBOutlet var lastnameField : UITextField = nil
  
  var indexPath = NSIndexPath()
  var receivedPerson:AddrBook[]=[]
  
  init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
      super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
  }
  
  init(coder aDecoder: NSCoder!) {
      super.init(coder: aDecoder)
  }
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      if !receivedPerson.isEmpty {        // If selected row in tableview in MainTableViewController
          currentOperation.text = "Edit Person"
          firstnameField.text = receivedPerson[indexPath.row].firstname
          lastnameField.text = receivedPerson[indexPath.row].lastname
      }
      else {       // If pressed "+" in MainTableViewController
          currentOperation.text = "Add Person"
      }
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
  }
  
  @IBAction func saveButton(sender : AnyObject) {
  
      let appDelegate:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
      let context:NSManagedObjectContext = appDelegate.managedObjectContext
  
      if receivedPerson.isEmpty {      // If pressed "+" in MainTableViewController
          let projectEntity = NSEntityDescription.entityForName("Person", inManagedObjectContext: context)
          var newPerson = AddrBook(entity: projectEntity, insertIntoManagedObjectContext: context)
          newPerson.lastname = lastnameField.text
          newPerson.firstname = firstnameField.text
      }
      else {       // If selected row in tableview in MainTableViewController
          receivedPerson[indexPath.row].firstname = firstnameField.text
          receivedPerson[indexPath.row].lastname = lastnameField.text
      }
  
      context.save(nil)
      self.navigationController.popViewControllerAnimated(true)
  }
  
  }
  </code></pre>
  
  <p>Class <code>AddrBook.swift</code> for CoreData:</p>
  
  <pre><code>import UIKit
  import CoreData
  
  @objc(AddrBook)
  class AddrBook: NSManagedObject {
  
      @NSManaged var lastname:String
      @NSManaged var firstname:String
  }
  </code></pre>