这是一个根据当前时间过滤具有开始时间和结束时间的数组的示例。这工作正常:
问题:但在这里我想知道谓词选择值的 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]];
Your shortPrograms
数组包含对象的子集collectionArr
。听起来你想从中获取一个对象shortPrograms
并确定在哪里collectionArr
它来自。
一般来说你不能。但如果所有的对象collectionArr
是独一无二的,那么就有可能。
id someObject = shortPrograms[someIndex]; // get some value
NSUInteger originalIndex = [collectionArr indexOfObject:someObject];
如果你的对象在collectionArr
不是唯一的,那么这将不起作用,因为无法知道您正在处理哪些重复项。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)