Search code examples
iphonearraysdictionarynsdatenspredicate

Nspredicate between


Can I apply NSPredicate for filter array of dictionary data corresponding to date?

NSPredicate *betweenPredicate =[NSPredicate predicateWithFormat: @"attributeName BETWEEN %@", @[@1, @10]];
NSDictionary *dictionary = @{ @"attributeName" : @5 };
BOOL between = [betweenPredicate evaluateWithObject:dictionary];
if (between) 
{
    NSLog(@"between");
}

Solution

  • I got solution to set below format of the predicate for filter myArray by date.

    Its really fast when we have huge amount of data in the array.

    NSArray *filteredarray = [myArray filteredArrayUsingPredicate:[NSPredicate 
    predicateWithFormat:@"(EventStartDateForMonthview <=  %@) AND 
    (EventEndDateForMonthview >=  %@)", strOndate,strOndate]];
    

    Thanks