現在の時刻に従って開始時刻と終了時刻を持つ配列をフィルタリングする例を次に示します。これはうまくいきます:
QUESTION : しかし、ここで述語が値を選択する 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]];