‘YearCalendarUnit’ was deprecated in OS X version 10.10: Use NSCalendarUnitYear instead

i0S Swift Issue

Question or problem in the Swift programming language:

My code:

 let calendar = NSCalendar.currentCalendar()
 let dateComponents = calendar.components(NSCalendarUnit.YearCalendarUnit | NSCalendarUnit.MonthCalendarUnit | NSCalendarUnit.DayCalendarUnit, fromDate: self)

My error:

'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

But I can’t type
NSCalendarUnitYear as well as (NSCalendarUnitMonth/ NSCalendarUnitDay)
What is wrong?

How to solve the problem:

Use let dateComponents = calendar.components(.CalendarUnitYear | .CalendarUnitMonth | .CalendarUnitDay, fromDate: self)

Edit:

This is because the error messages are for Objective-C, not adapted for swift.

Edit 2: see Will’s comment for Swift 2 and on.

Hope this helps!