我的代码:
let calendar = NSCalendar.currentCalendar() let dateComponents = calendar.components(NSCalendarUnit.YearCalendarUnit | NSCalendarUnit.MonthCalendarUnit | NSCalendarUnit.DayCalendarUnit,fromDate: self)
我的错误:
'YearCalendarUnit' was deprecated in OS X version 10.10: Use NSCalendarUnitYear instead 'MonthCalendarUnit' was deprecated in OS X version 10.10: Use NSCalendarUnitMonth instead 'DayCalendarUnit' was deprecated in OS X version 10.10: Use NSCalendarUnitDay instead
但我不能键入
NSCalendarUnitYear以及(NSCalendarUnitMonth / NSCalendarUnitDay)
哪里不对?
解决方法
使用let dateComponents = calendar.components(.CalendarUnitYear | .CalendarUnitMonth | .CalendarUnitDay,fromDate:self)
编辑:
这是因为错误消息是针对Objective-C的,不适用于swift.