1
In user registration I have an input with a mask in this format "dd/MM/YY", after taking the value of the input, which comes as a string, I have to convert it to date. The conversion always worked, only with the date 25/10/1992 it of the problem and always returns nil. The code I’m using is this:
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM/yyyy"
if let dateString = birthDayInput.text { // 25/10/1992
return dateFormatter.date(from: dateString) // nil
}
return nil
Instead of using
isLenient = true
just configure the Dateformatter calendardateFormatter.calendar = Calendar(identifier: .gregorian)
. Another important thing when this Parsing dates with fixed format is to use thedateFormatter.locale = Locale(identifier: "en_US_POSIX")
– Leo Dabus