I have problem with my code. I want compare two dates, but it write erorr.
fatal error unexpectedly found nil while unwrapping an optional value
It write date3 is nil, but it isn't.
let sweetObject = Task(snapshot: sweet as! FIRDataSnapshot)
let dateString3 = sweetObject.dueDate //Is June 11, 2017
let dateFormatter3 = DateFormatter()
dateFormatter3.dateFormat = "MMM dd, yyyy"
let date3 = dateFormatter3.date(from: dateString3!)
let dateString = "Jan 28, 2017"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM dd, yyyy"
let date = dateFormatter.date(from: dateString)
if date3! < date!{
print("Due date is earlier than today!")
}
If I add this condition, it write "ok" to console.
if date3 != nil {
print("ok")
}
What I do bad and what is the problem and how solve it?