Aster将我的项目从swift2.3更新为swift 3我收到此错误:无法使用参数列表'(rawValue:UInt)调用'NSCalendar.Unit.Type'类型的值 在swift3 NScalender中重命名为Calendar但是如何在这段代码中使用日历类?':
private func calendar(_ calendar: TKCalendar, eventsForDate date: Date) -> [AnyObject]? {
let components = self.calendarView.calendar.component(NSCalendar.Unit(rawValue: NSCalendar.Unit.Year.rawValue|NSCalendar.Unit.Month.rawValue|NSCalendar.Unit.Day.rawValue), from: date)
components.hour = 23
components.minute = 59
components.second = 59
let endDate = self.calendarView.calendar.dateFromComponents(components)
let predicate = NSPredicate(format: "(startDate <= %@) AND (endDate >= %@)", endDate!, date)
let result: NSArray = self.events.filteredArrayUsingPredicate(predicate)
return result as [AnyObject]
}
答案 0 :(得分:0)
这是因为Calendar类中有3个快速更改。
将其更改为 -
let components = self.calendarView.calendar.dateComponents([.day, .month, .year], from: date)