Answer the question
In order to leave comments, you need to log in
Cannot assign value of type 'Date?' to type 'String?' how to overcome?
Cannot assign value of type 'Date?' to type 'String?' <- gives this error next to cell.dateLabel.text = clnt.zakazDate. how to overcome?
It appeared after the core data where the date is stored changed the type from String to Date
Answer the question
In order to leave comments, you need to log in
You need to do the formatting, use the DateFormatter:
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/mm/yyyy"
cell.dateLabel.text = dateFormatter.string(from: clnt.zakazDate)
extension Date {
func dayMonthYearFormat() -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/mm/yyyy"
return dateFormatter.string(from: self)
}
}
// usage:
ell.dateLabel.text = clnt.zakazDate.dayMonthYearFormat()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question