[NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance

I would like to compare the difference between the two dates, but with the code below I got the error "[NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance". What is wrong with the code?

NSDate *dateAdded=[eventDictionary objectForKey:@"dateAdded"]; NSDate *validUntilDate=[eventDictionary objectForKey:@"validUntilDate"]; NSDateComponents *sometimeAgo = [[NSCalendar currentCalendar] components:(NSSecondCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:dateAdded toDate:validUntilDate options:0]; 
+4
source share
2 answers

It appears that dateAdded and / or validUntilDate are strings, not dates. These may be strings representing dates, but strings in the end.

+8
source

You need to use NSDateFormatter to convert date strings to actual NSDates.

+4
source

All Articles