The main question I'm sure is the simple answer.
I am trying to get the timestamp of a photo. When I try to access NSDateComponents to get a specific date element (for example, "day"), I get an EXC_BAD_ACCESS error.
First, the corresponding bits of my code:
NSDate *takenAt = [[NSDate alloc] initWithString:formattedDateString];
NSLog(@"date: %@", takenAt);
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSLog(@"cal: %@", gregorian);
NSUInteger unitFlags = (NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit);
NSDateComponents *components = [gregorian components: unitFlags
fromDate: takenAt
];
int days = [components hour];
NSLog(@"comp: %@", days);
If I comment on the final line: NSLog (@ "comp:% @", days); The code runs successfully.
I tried several options, but the bottom line says that at any time when I send a message to the components to access the property, the error "EXC_BAD_ACCESS" occurs.
, , , , , , , , . , , .
?
, . Objective-C.
NSDateComponents.