How do I get current year as string in Obj-C ?
Also how do I compare the same using another year value ?
Is it advisable to do a string comparision OR dirctly ye
NSCalendar *gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
NSInteger year = [gregorian component:NSCalendarUnitYear fromDate:NSDate.date];
Note: there are several calendar identifiers besides NSGregorianCalendar. Use whatever is appropriate for your locale. You can ask for whatever set of components you'd like by bitwise OR'ing the fields together (e.g., NSYearCalendarUnit | NSMonthCalendarUnit) and using components:fromDate
instead. You can read about it in the Date and Time Programming Guide.
With calendar components as primitive types, comparisons are efficient.