-1

Given a NSDate I would like to compute the next n days.

Is there a way from a calendar object to get the next day component? In this way I could write a recursive function to get the next n NSDates without having to write my own "next day" function.

For example: if today is the 28th of February I do not want to write an algorithm to compute today + 3 days and get 3rd of March or 2nd of March according to the type of year. I would like instead to have something like: get_next_day from a date.

Here is my code so far:

NSDate * now = [NSDate date];
NSCalendar * calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:now];

NSInteger day = [components day];
NSInteger month = [components month];
NSInteger year = [components year];

// Is there a way to get the next day without having to breakdown the components and compute it myself?
mm24
  • 9,280
  • 12
  • 75
  • 170

1 Answers1

0

You need to do it via your date components. So,

components.day = components.day + 1;
newDate = [[NSCalendar currentCalendar] dateFromComponents:components]; 
Gismay
  • 784
  • 9
  • 17