I've got a bug here apparently, and I can't find it. The output of this program is 0, when it should be 7. What am I doing wrong? The
components variable is null after initialization for some reason. Therefore nothing is returned from [components day].
(I realize that we're supposed to make a new elapsedDays method, but for the sake of simplicity I need to figure out what's wrong here first).
NSDate *now = [[NSDate alloc] init];
NSTimeInterval secondsPerWeek = 24 * 60 * 60 * 7;
NSDate *oneweekfromnow = [[NSDate alloc] initWithTimeIntervalSinceNow:secondsPerWeek];
NSCalendar *mycalendar = [[NSCalendar alloc] init];
NSDateComponents *components = [mycalendar components:NSDayCalendarUnit fromDate:now toDate:oneweekfromnow options:0];
NSInteger days = 0;
days = [components day];
NSLog(@"The elapsed days are %li", (long) days);