I am attempting to take a string in the format dd/mm/yyyy and convert it to an NSDate so I can store a birthday. The day, month, and year are validated to be a real date (not in the future either) so I know that they are correct. They are entered as text fields by the user and I suppose I could make the dateString any format I want it that would be helpful.
let day = dayTextField.text
let month = monthTextField.text
let year = yearTextField.text
let dateString = "\(day)/\(month)/\(year)"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM/yyyy"
let birthdate: NSDate = dateFormatter.date(from: dateString) as NSDate
My problem is with the last line when I attempt to cast my date string to an NSDate, I get the following error:
'Date?' is not convertible to 'NSDate'; did you mean to use 'as!' to force downcast?
I could force cast after "(from: dateString)" but I didn't think that would be the right thing to do.
Any help and insight you can provide would be greatly appreciated! Thank you