I have the following code:
for dates in calendar.selectedDates {
for dateOfEvent in myEventDate {
formatter.dateFormat = "dd MM yyyy"
let dateToCompare = formatter.string(from: dates)
if dateOfEvent == dateToCompare {
formatter.dateFormat = "dd MM yyyy"
let comparingDate = formatter.date(from: dateToCompare)
}
Does anyone could please explain to me why comparingDate is nil?? I'm loosing it...
UPDATE-------- In this for loop everything is working fine. I'm getting the date selected by the user from a calendar (dates) and dateOfEvent is a date (string) which get from coredata. Until the if statement everything is working fine. When I try to format the dates in this format "dd MM yyyy" the the result is nil
--------UPDATE
or dates in calendar.selectedDates {
for dateOfEvent in myEventDate {
formatter.dateFormat = "dd MM yyyy"
let dateToCompare = formatter.string(from: dates)
if dateOfEvent == dateToCompare {
formatter.timeZone = Calendar.current.timeZone
formatter.locale = Calendar.current.locale
formatter.dateFormat = "dd MM yyyy"
let comparingDate = formatter.date(from: dateToCompare)
print(comparingDate)