I have an app which populates a UITextField by selecting a date from a UIDatePicker. I noticed some isolated issues where the app had crashed after the user tapped the UITextField to revise a date using the DatePicker. What I now realize is that the user had changed the Region Format on the device after they had already entered a date into the textfield. When they returned later to revise the date, the DatePicker no longer recognized the date format.
What would be considered "best practice" for handling dates, region formats in this sort of situation?
Some of my ideas for handling this include one or more of the following:
- Use Try-Catch block to prevent a crash and reset the date to today's date. Then alert the user that the Region Format has changed since they last modified the date.
- Force a format onto the user using setLocale in a date formatter. Not crazy about this idea as I think the user should be free to select and change their preferred Region Format anytime.
- Store the Region Format in NSUserDefaults and check it against the current Region Format on the device each time the user changes a date. If they don't match then alter the date format to match the new region.
Not sure which way to go with this. I would appreciate your feedback.
Thanks in advance.