-1

if let created = _dictionary[kCREATEDAT] {

      createdAt = dateFormatter().date(from: created as! String)! //Fails here 
    }else {

        createdAt = Date()

    }

Error message Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

Fpsayo
  • 1
  • 1

1 Answers1

0

Thats exactly what you asked for by using the ! operator. Use "if let" or "guard" to check for errors and handle them instead.

if let created = _dictionary[kCREATEDAT] as? String, 
   let createdAt = dateFormatter().date(from: created) {
}
gnasher729
  • 51,477
  • 5
  • 75
  • 98