Imagine you had an NSDate object and want to add several days to it. We can use NSDate method dateByAddingComponents for this, which takes – as you may have guessed – NSDateComponents as parameters.
In this example, let’s assume we want to know what date it is 5 days from today:
int daysToAdd = 5;
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [[NSDateComponents alloc]init];
NSDate *futureDate = [gregorian dateByAddingComponents:components toDate:today options:0];
You can add as many and diverse components you like, such as
Check out the NSDateComponents Class Reference for more information.