Generate NSDate from day, month, and year
Apart from the typo nowadays (2019) there is a more convenient syntax to access dictionary values with key subscription and properties with dot notation
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
NSNumber *day = dataSource[@"day"];
NSNumber *month = dataSource[@"month"];
NSNumber *year = dataSource[@"year"];
components.day = day.integerValue;
components.month = month.integerValue;
components.year = year.integerValue;
NSDate *_date = [calendar dateFromComponents:components];
and there is another API without date components
NSCalendar *calendar = [NSCalendar currentCalendar];
NSNumber *day = dataSource[@"day"];
NSNumber *month = dataSource[@"month"];
NSNumber *year = dataSource[@"year"];
NSDate *_date = [calendar dateWithEra:1 year:year.integerValue month:month.integerValue day:day.integerValue hour:0 minute:0 second:0 nanosecond:0];
You are calling setMonth twice, the second time with the value for year. Should be:
[components setDay:[day intValue]];
[components setMonth:[month intValue]];
[components setYear:[year intValue]];
You have a typo in your code: (last line should be setYear:
)
[components setDay:[day intValue]];
[components setMonth:[month intValue]];
[components setYear:[year intValue]];
One glaring glitch is:
[components setMonth:[year intValue]]; //setting month with year!