-3

My code

I try to search this issue in SOW, comment part is not avaiable now,my Xcode is 7.1 and iOS 9.0 Simulator fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

how to solve this issue? thank you

I removed as! ,but xcode suggest me append as.......

var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(cellId)! as UITableViewCell

Jet
  • 11
  • 3
  • 1
    remove the `! as UITableViewCell` – dan Jun 27 '16 at 14:58
  • 1
    This is probably the most common issue the new Swift developers can have, there are hundreds of answers on SO, you can find a very detailed explanation at some of them or at every Swift cookbook. What interests me is the part "comment part is not available now", could you elaborate ? – A-Live Jun 27 '16 at 15:05

2 Answers2

0

Way too much code.

let cell = UITableViewCell(style: .Default, reuseIdentifier: cellId)

It won't be nil unless your tableview's reuseIdentifier isn't correct.

Pranav Wadhwa
  • 7,666
  • 6
  • 39
  • 61
0

I would use

let cell = tableView1.dequeueReusableCellWithIdentifier(cellId, forIndexPath: indexPath) as! UITableViewCell

That means that the cell with the correct ID will be placed into the correct space on the UITableView. Also, I think that having tableView at the front might have caused the error, so I changed it to tableView1.

Marco
  • 2,004
  • 15
  • 24