简体   繁体   中英

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)'

thanks in advance

Regards, 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)
   ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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