views:

19

answers:

0

Hi everybody!

I have an array with about 6000 entries, everyone with a date, in the form of 4 integers (year, month, day, hour). I want to find all the entries with a given day, and i'm doing like this:

NSCalendar *gregorian = [[NSCalendar alloc]
                         initWithCalendarIdentifier:NSGregorianCalendar];

unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSHourCalendarUnit;
NSDateComponents *comps = [[gregorian components:unitFlags fromDate:date]retain];

[gregorian release];

NSPredicate *predicate = [NSPredicate predicateWithFormat:
                          @"anno == %d AND mese == %d AND giorno == %d", [comps year], [comps month], [comps day]];

[comps release];

NSArray *filtered = [dataArray filteredArrayUsingPredicate:predicate];

But the search is very slow! (takes about 3 secs on the 2G iPhone).

Is there a way to speed this up?

Or is there a better way to do this?