Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

macos

ios

swift

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?

like image 760
Huynh Inc Avatar asked Apr 10 '15 07:04

Huynh Inc


1 Answers

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.

like image 192
Schemetrical Avatar answered Nov 16 '22 00:11

Schemetrical