saman01
saman01

Reputation: 1004

Can't figure out this NSDateComponents error

I have the following statements:

NSDate *Today = [NSDate dateWithTimeIntervalSinceNow:0];
NSDate  *cDate =  [Lines objectAtIndex:(NSUInteger) 0];
NSLog(@"cDate: %@  Today: %@", cDate, Today); 
NSCalendar *calendar = [NSCalendar currentCalendar];
NSInteger desiredComponents = (NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit);
NSDateComponents *secondComponents = [calendar components:desiredComponents fromDate:Today];
NSDateComponents *firstComponents  = [calendar components:desiredComponents fromDate:cDate]; 

NSLog statement prints:cDate: 2011-08-16 18:35:29 +0000 Today: 2011-08-17 15:53:19 +0000

The last statement (firstComponents) which is very similar to the previous statement(secondComponents) crashes with the following error: unrecognized selector sent to instance

Thanks for any help.

Upvotes: 1

Views: 112

Answers (1)

Johan Kool
Johan Kool

Reputation: 15927

Check if cDate really is an instance of NSDate. It could also be for example an NSString instance with the value "2011-08-16 18:35:29 +0000".

Upvotes: 2

Related Questions