let dobInput = DOB.text
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM/dd/yyyy"
Setting a date format string like this is a really bad idea. Even within the English-speaking world, everyone outside of North America will hate you forever if you force them to use the wacky month-first US date format (-:
In most cases you’ll want to set up the date formatter via one or both of its
dateStyle
and
timeStyle
properties. For example:
let df = DateFormatter()
df.dateStyle = .short
print(df.string(from: Date()))
// Prints "04/12/2017", on my UK English system today.
However, if you’re inputting dates on iOS it might be better to use
UIDatePicker
. In general entering text is a bit of a challenge on iOS, so using something like the date picker makes for a better UI.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"