title: iOS- Getting months and year over 2 yrs period
body: <p>I'm new to iOS and i'm having a hard time getting months and years for a period of 2 yrs. i'm putting them into an <code>NSArray</code>. All I can get is one year, but beyond that, the years don't increment to reflect year change. Please help?  Thanks</p>
  
  <pre><code>NSDate  *todayDate = [NSDate date];
  NSDateComponents *todayComponents=[[NSCalendar currentCalendar]      components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:todayDate];
  NSMutableArray  *monthNameArray   = [[NSMutableArray alloc] init];
  
  int currentMonth = [todayComponents month];
  int currentYear = [todayComponents year];
  int nextYear = currentYear + 1;
  
  int month = 1;
  int year;
  for(int m = currentMonth ; month &lt;= 12; m++){
  
      int nextMonth = m % 12;
  
      if(nextMonth &lt; currentMonth){
          year = nextYear;
      } else {
          year = currentYear;
      }
      NSString *allMonths = [NSString stringWithFormat:@"%@ %d",[[dateFormatter monthSymbols]objectAtIndex:nextMonth], year];
      [monthNameArray addObject:allMonths];
      month++;
  </code></pre>