我在检查日期时崩溃了:
func cehckForDate(date: String?) -> Int{
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
let fromDt = dateFormatter.date(from: date ?? "")
let curreentDate = Date()
let order = Calendar.current.compare(curreentDate , to: fromDt!, toGranularity: .day)
switch order {
case .orderedAscending:
return(2)
case .orderedDescending:
return(1)
case .orderedSame:
return(0)
}
return 0
}
我的崩溃在这里:
let order = Calendar.current.compare(curreentDate , to: fromDt!, toGranularity: .day)
我正在nil
为fromDt
我的约会对象是 2018-08-16 15:04:17