Having issues trying to convert this to Swift 3.0.
I have:
public func calendarView(_ view: DDCalendarView, eventsForDay date: Date) -> [Any]? {
let daysModifier = (date as NSDate).days(from: Date())
//var daysMod = date.days(from: Date())
//var newE = self.events(forDay: daysModifier as Int) as NSArray
var Good = self.events(forDay: daysModifier) as Any
var dates = [NSMutableArray]()
var e:DDCalendarEvent
for e in Good as! [AnyObject] {
if e.dateBegin(isEqual(date)) as! Bool == true || e.dateEnd(isEqual(date)) as! Bool == true {
dates.append(e as! NSMutableArray)
}
}
return dates
}
the condition if e.dateBegin(isEqual(Date)){} is giving this error. while in Objective-C Code Code is:
- (NSArray *)calendarView:(DDCalendarView *)view eventsForDay:(NSDate *)date {
//should come from db ;) NOW using testdata
NSInteger daysMod = [date daysFromDate:[NSDate date]];
NSArray *newE = [self eventsForDay:daysMod]; //always today ;)
NSMutableArray *dates = [NSMutableArray array];
for (DDCalendarEvent *e in newE) {
if([e.dateBegin isEqualDay:date] ||
[e.dateEnd isEqualDay:date]) {
[dates addObject:e];
}
}
return dates;
}
and its returning Bool Value for isEqualDay Function
- (BOOL)isEqualDay:(NSDate *)date {
NSDateComponents *compA = self.currentCalendarDateComponents;
NSDateComponents *compB = date.currentCalendarDateComponents;
return ([compA day]==[compB day] && [compA month]==[compB month ]&& [compA year]==[compB year]);
}
Any Solution for this?
This line:
if e.dateBegin(isEqual(date)) as! Bool == true || e.dateEnd(isEqual(date)) as! Bool == true {
should be:
if e.dateBegin.isEqualDay(date) == true || e.dateEnd.isEqualDay(date) == true {
This assumes you have also translated the isEqualDay:
method as an extension function on Date
.
BTW - there are many other problems in your translation. The above only covers that one specific line you ask about in your question.
The following should be what you want:
public func calendarView(_ view: DDCalendarView, eventsForDay date: Date) -> [Date] {
let daysModifier = date.days(from: Date()) // return Int
let newE = self.events(forDay: daysModifier) // return [DDCalendarEvent]
var dates = [Date]()
for e in newE {
if e.dateBegin.isEqualDay(date) == true || e.dateEnd.isEqualDay(date) == true {
dates.append(e)
}
}
return dates
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.