Basic question to which I'm sure there is a simple answer.
I'm trying to get the timestamp of a photo. When I try to access the NSDateComponents to retrieve a specific date element (say "day" for example), I get a EXC_BAD_ACCESS error.
First, the relevant bits of my code:
// formattedDateString is a string representing the "DateTimeOriginal" EXIF property extracted from the image
NSDate *takenAt = [[NSDate alloc] initWithString:formattedDateString];
NSLog(@"date: %@", takenAt); // prints= date: 2010-01-10 03:25:00 -0500
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSLog(@"cal: %@", gregorian); // prints= cal: <__NSCFCalendar: 0x10020b570>
NSUInteger unitFlags = (NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit);
NSDateComponents *components = [gregorian components: unitFlags
fromDate: takenAt
];
int days = [components hour];
NSLog(@"comp: %@", days); // thrown error= Program received signal: “EXC_BAD_ACCESS”
If I comment out the final line: NSLog(@"comp: %@", days); the code executes successfully.
I've tried a few variants on this but the bottom line is that any time I send a message to components to access a property the "EXC_BAD_ACCESS" error is raised.
The research I did seems to indicate that this is typically the result of an uninitialized pointer or an object that I've tried to release that isn't mine to release. From what I can tell that's not the case here.
What am I missing?
Thanks in advance for shedding some light on this for me. This is one of my first explorations in Objective-C.