NSDate *dateOfEvent = wi.date;
dNSLog (@"dateOfEvent is %@", wi.date);
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:dateOfEvent];
dNSLog (@"weekdayComponets is %@", weekdayComponents);
// TODO: Return "Week of [date of Sunday of the week]"
return [NSString stringWithFormat:@"%ld-%ld-%ld", [weekdayComponents month], [weekdayComponents day], [weekdayComponents year]];
The NSDate is working exactly the way it should. However, the return string is resulting in the int value 2147483647 (which I believe is the maximum value of a signed int, or close to it). What's going on?
__________________
If I have helped you, please consider donating. I use PayPal. It would mean a lot to me!
NSDate *dateOfEvent = wi.date;
dNSLog (@"dateOfEvent is %@", wi.date);
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekdayComponents = [gregorian components:(NSYearCalendarUnit + NSMonthCalendarUnit + NSDayCalendarUnit + NSWeekdayCalendarUnit)) fromDate:dateOfEvent];
dNSLog (@"weekdayComponets is %@", weekdayComponents);
// TODO: Return "Week of [date of Sunday of the week]"
return [NSString stringWithFormat:@"%ld-%ld-%ld", [weekdayComponents month], [weekdayComponents day], [weekdayComponents year]];
The NSDate is working exactly the way it should. However, the return string is resulting in the int value 2147483647 (which I believe is the maximum value of a signed int, or close to it). What's going on?
If you want day, month, year and weekday components, you have to ask for them. You are only asking for day and weekday. You will get garbage if you ask the components objects for month and year, and will not get the values you want for day.
I changed the code above to ask for the units you need.
I'm also not sure if %ld is the right format. I use %d and get the correct results.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.