开发者

Can't figure out this NSDateComponents error

开发者 https://www.devze.com 2023-03-28 23:09 出处:网络
I have the following statements: NSDate *Today = [NSDate dateWithTimeIntervalSinceNow:0]; NSDate*cDate =[Lines objectAtIndex:(NSUInteger) 0];

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:cD开发者_StackOverflow中文版ate: 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.


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".

0

精彩评论

暂无评论...
验证码 换一张
取 消