developer developer - 4 months ago 75
iOS Question

NSYearCalendarUnit deprecated in iOS

I'm using

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;

Rob Rob

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]