我的代码:
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) 有什么问题?
答案 0 :(得分:14)
使用let dateComponents = calendar.components(.CalendarUnitYear | .CalendarUnitMonth | .CalendarUnitDay, fromDate: self)
编辑:
这是因为错误消息是针对Objective-C的,不适合swift。
编辑2:请参阅Will对Swift 2及其他人的评论。