I know that this topic is fully discussed here and in other forums. Unfortunately, I still cannot understand why the Date is nil.
Note that when I run the code in the Debugger or in Playground then it works totally fine. It's something to do with the fact that it runs on the device.
var dateString = "2019-12-17 3:48:02 PM"
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale.current
dateFormatter.timeZone = TimeZone.current
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss a"
let date = dateFormatter.date(from: dateString) // date is nil