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]];
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
Post a Comment