Questioner Questioner - 1 year ago 91
Swift Question

"Fatal error" crash at "if let"

I get a crash that has no information other than it's a fatal error. I can see it in 'Organiser' in Xcode and it points to the following line:

enter image description here

I can't reproduce it on a device where I work or on a simulator. It happens when someone uses a beta from TestFlight.

#0 (null) in specialized _fatalErrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> Never ()
#1 (null) in specialized _fatalErrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> Never ()
#2 (null) in ...TableViewController.tableView(UITableView, cellForRowAt : IndexPath) -> UITableViewCell at ...TableViewController.swift:103

More code:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "LCell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! LTableViewCell
let l = ls[(indexPath as NSIndexPath).row]
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = NSLocalizedString("dd/MM/yyyy", comment: "")

if let date ={
let dateString = dateFormatter.string(from: date)
cell.dateLabel.text = dateString

Answer Source

I seem to have solved the problem. It was happening when the user's phone had its date and time set to display in a 12 hour format. I read this answer and added the following line:

    dateFormatter.locale = Locale(localeIdentifier: "en_GB")

The crashes don't happen any more. I wish the crash logs weren't so useless. It would have saved a lot of my time.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download