Getting a crash when trying to pass the string into NSDateFormatter dateFromString method.
I checked out the docs but I dont see anything to explain what is going wrong.
NSError * errorX;
NSDictionary * attributesDict = [[fileManager attributesOfItemAtPath:imgPath error:&errorX ] retain];
NSString *theDate = [[attributesDict objectForKey:@"NSFileCreationDate"] retain];
[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:theDate];
Crash comes from the last line.
erminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDate length]: unrecognized selector sent to instance 0x1bd380'
Anybody able to point me where I’ve gone off track?
Thanks,
-Code
[attributesDict objectForKey:@"NSFileCreationDate"]will return an NSDate, not an NSString. So at that point, you already have the NSDate you are looking for, there is no need to use NSDateFormatter to parse it. In fact, you can’t of course because dateFromString: requires a string.BTW, you have a couple memory management issues here, unrelated to your question.