ios – “YearCalendarUnit”在OS X 10.10版中被弃用:使用NSCalendarUnitYear

前端之家收集整理的这篇文章主要介绍了ios – “YearCalendarUnit”在OS X 10.10版中被弃用:使用NSCalendarUnitYear前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的代码
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.

猜你在找的iOS相关文章