ios - Get the upcoming month from NSArray -


i have array month , year.for ex array {jan 2015,feb 2015, june 2015, september 2015}. want index of current month , getting it. if there no current month, want upcoming recent month.in above example want index of september 2015.

help appreciated.

below code index of current month.

   if ([titlemonth isequaltostring:currentmonth])      {      indexnumber=[[self.databymonth valueforkey:@"title"]indexofobject:currentmonth];      } 

here getting current month nsdate.

create nsdatacomponents

first, need fill array nsdatecomponents objects. @ this method in particular.

for example. create nsdatecomponents current month.

nsdatecomponents *datecomponents = [[nscalendar currentcalendar]components:(nscalendarunitmonth | nscalendarunityear) fromdate:[nsdate date]];  

  • then fill array these components.
  • loop through array until current month , year equal or lesser looping month , year. if equal, have current month. if lesser, item in array next month/year.

    would work?
    here rough sample code

    for(nsdatecomponents *components in arrayofmonths) {     if(currentmonth.date == components.date)         nslog(@"current month on list");     else if(currentmonth.date < components.date)     {         nslog(@"this next month on list");         break;     } } 

  • Comments

    Popular posts from this blog

    Magento/PHP - Get phones on all members in a customer group -

    php - .htaccess mod_rewrite for dynamic url which has domain names -

    Website Login Issue developed in magento -