这是一个根据当前时间过滤具有开始时间和结束时间的数组的示例。这工作正常:
问题:但在这里我想知道 collectionArr 的索引位置,谓词选择值。
NSDate* currentDate = [NSDate date];
NSDateFormatter *_formatter = [[[NSDateFormatter alloc] init] autorelease];
[_formatter setLocale:[NSLocale currentLocale]];
[_formatter setDateFormat:@"yyyy-MM-dd hh:mm a"];
NSString *_date=[_formatter stringFromDate:currentDate];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"StartDate <= %@ AND EndDate = %@", _date, _date];
if (shortPrograms.count > 0) {
[shortPrograms removeAllObjects];
}
//collectionArr have multiple dictionaries ,which has start date and end date.
//collectionArr = [[NSArray alloc] initWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"..Sdate..",@"Startdate",@"..Edate..",@"Enddate", nil], nil];
//shortPrograms is a filter are, having the date in between start date and end date.
[shortPrograms addObjectsFromArray:[collectionArr filteredArrayUsingPredicate:predicate]];