0

I want to create a simple if function which carries out a bit of code depending on if the current iDevice year is 2012. I have tried to use NSCalendar and NSDateComponents in Xcode for this but have failed... :(

Anyone know of any good resources or blogs with tutorials/advice on this kind task?

Thanks,

Dan

Supertecnoboff
  • 6,406
  • 11
  • 57
  • 98

1 Answers1

2
NSDate *date = [NSDate date];
NSCalendar *gregorian = [[[NSCalendar alloc]
                         initWithCalendarIdentifier:NSGregorianCalendar] autorelease];

NSDateComponents *components = [gregorian components:NSYearCalendarUnit fromDate:date];
int year = components.year;
Kreiri
  • 7,840
  • 5
  • 30
  • 36
  • Thank you so much. It worked like a charm, I had to edit it a bit because my Xcode project has ARC enabled. But thanks very much :) – Supertecnoboff Oct 25 '12 at 14:55