Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSYearCalendarUnit deprecated in iOS

I'm using NSYearCalendarUnit NSMonthCalendarUnit NSDayCalendarUnit but unfortunately, these "Calendar Units" are reported as deprecated first in IOS 8.0. What's the alternative of them, or how do I avoid these warnings.

unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit; 
like image 779
developer Avatar asked Dec 28 '14 14:12

developer


1 Answers

Use NSCalendarUnitYear:

NSCalendarUnit unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth |  NSCalendarUnitDay; 

I infer from the code sample in the original question that you were looking for Objective-C answer, but for those looking for Swift equivalent, you would do:

let unitFlags: NSCalendarUnit = [.Year, .Month, .Day] 

Note, in Swift 3, the equivalent would be:

let unitFlags: Set<Calendar.Component> = [.year, .month, .day] 
like image 167
Rob Avatar answered Sep 23 '22 20:09

Rob