1

我可以将 NSPredicate 应用于与日期对应的字典数据的过滤器数组吗?

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

2 回答 2

2

我得到了设置以下格式的谓词以按日期过滤 myArray 的解决方案。

当我们在数组中有大量数据时,它真的很快。

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

谢谢

于 2013-10-08T05:15:46.913 回答
0

有了开始和结束日期范围后,将谓词用作

NSDate * startDate,*endDate;


// Your logic to calculate range


NSPredicate * predicate = [NSPredicate predicateWithFormat:@"(%K <= %@) AND (%K >=  %@)",@"attributeName",startDate,@"attributeName",endDate]];

BOOL isContainObjects = [myArray filterArrayUsingPredicate:predicate]count];
于 2019-05-23T10:08:15.793 回答