-2
 func createDatePicker() {
    datePicker?.preferredDatePickerStyle = .wheels
    datePicker?.datePickerMode = .date
    dateTextField.inputView = datePicker
    dateTextField.inputAccessoryView = createToolBar()
}

@objc func donePressed() {
    let dateFormatter = DateFormatter()
    dateFormatter.dateStyle = .medium
    dateFormatter.timeStyle = .none

    self.dateTextField.text = dateFormatter.string(from: datePicker!.date)
    self.view.endEditing(true)
}

This code is in firstViewController for datePicker, and in the secondViewController I have this error. I want to make counting down days from today to date selected with picker.enter image description here

ifF3
  • 31
  • 9
  • 1
    The date format most likely does not match the date string being passed in. – luk2302 Jan 26 '21 at 13:09
  • 1
    You crash on `date(from:)` and show only the code of `.string(from:)`. We don't know how liiks like `dateOfEvent`, and the formatter use has no format? – Larme Jan 26 '21 at 13:10
  • 1
    Related: https://stackoverflow.com/questions/35700281/date-format-in-swift – vadian Jan 26 '21 at 13:33

1 Answers1

-1

dateFormatter.dateFormat should match the date string you are passing.

check this Date Format in Swift

m_k_s
  • 54
  • 3