I am new to the swift library. I am using the calendar in swift and I want to show the events in calendar. The events are obtained from the Json API but when I compare the date it is showing an error.
This is the code
let data = event["date"] as? String
let newString = data?.replacingOccurrences(of: "/", with: "-")
self.FirstData = self.EventDates[0]
compare function
func compareDate(date : String){
let date = date
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
====>>>>Error in line
let dateFromString : NSDate = dateFormatter.date(from: date)! as NSDate
dateFormatter.dateFormat = "yyyy-MM-dd"
let datenew = dateFormatter.string(from: dateFromString as Date)
print("datee",datenew)
}
Error: fatal error: unexpectedly found nil while unwrapping an Optional value
How to compare date or resolve this issue.