简体   繁体   English

数组中的相邻日期元素

[英]adjacent date element in array

how to compare an adjacent array element that contains date. 如何比较包含日期的相邻数组元素。 The thing is when i compare 事情是当我比较

BOOL day = [[temp_date objectAtIndex:k] compare:[temp_date objectAtIndex:k+1]];

it throughs the following expection 通过以下期望

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSCFArray objectAtIndex:]: index (23) beyond bounds (23)' *由于未捕获的异常“ NSRangeException”而终止应用程序,原因:“ * -[NSCFArray objectAtIndex:]:超出范围(23)的索引(23)”

thanks in advance 提前致谢

Regards, sathish 问候,sathish

It seems you do everything correct, just check that you're always within array's bounds. 看来您所做的一切都正确,只需检查自己始终在数组范围内即可。 If you do that in a loop the condition may be: 如果您循环执行此操作,则条件可能是:

for (int k = 0; k+1 <temp_date.count; ++k)
   ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM