I have a small error in NSDateFormatter()
. When I start the application, it loads it and shows me the date, but when I change the month and go through the function again, it gives me an error.
func supplementaryView(shouldDisplayOnDayView dayView: DayView) -> Bool {
let dateformatter = NSDateFormatter()
dateformatter.dateFormat = "yyyy-MM-dd"
let date2 = dateformatter.stringFromDate(dayView.date.convertedDate()!)
let date_Array = ["2016-02-10","2016-02-11","2016-02-12","2016-01-11"]
for(var i=0;i<date_Array.count;i++)
{
if(date2==date_Array[i])
{
return true
}
return false
}
The problem is in dateformatter.stringFromDate(dayView.date.convertedDate()!)
Since you are converting to a String.
The error is fixed. The problem comes from the dayView since you have to specify the Day, Month and year. I leave the code fixed.
func supplementaryView(shouldDisplayOnDayView dayView: DayView) -> Bool {
let dateformatter = NSDateFormatter()
dateformatter.dateFormat = "yyyy-MM-dd"
let date_Array = [[2016,02,10],[2016,02,11],[2016,02,12],[2016,01,11]]
for(var i=0;i<date_Array.count;i++)
{
if let date = dayView.date {
if(date.day == date_Array[i][2] && date.month == date_Array[i][1] && date.year == date_Array[i][0]) {
return true
}
} else {
}
}
return false
}
What we do is specify the day, month and year and the error does not come out anymore, because when it goes through the for if it will no longer give an error.