尝试将此转换为Swift 3.0时遇到问题。
我有:
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
}
如果e.dateBegin(isEqual(Date)){}给出此错误的条件。 而在Objective-C代码中则是:
- (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;
}
及其为isEqualDay函数返回的Bool值
- (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]);
}
任何解决方案?
答案 0 :(得分:1)
这一行:
if e.dateBegin(isEqual(date)) as! Bool == true || e.dateEnd(isEqual(date)) as! Bool == true {
应该是:
if e.dateBegin.isEqualDay(date) == true || e.dateEnd.isEqualDay(date) == true {
这假设您已将isEqualDay:
方法翻译为Date
上的扩展功能。
以下内容应该是您想要的:
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
}