我有一个主数组 ( arrayEvents
) 包含事件列表,其中包含 start_date、event_id、event_name 等字段,许多事件可以在同一日期但不同时间发生。因此,我只使用唯一日期 ( arrayDates
) 来检查并将其与当前日期(currentDate
其范围从一个月的第一天到一个月的最后一天)进行比较,以显示特定日期的事件。我到此为止。现在我的问题是,我需要更新arrayEvents
以供以后比较,所以我应用以下逻辑...but I am in the middle of the sea
并且不知道去哪里!
for(int i=0;i<[arrayDates count];i++) {
NSDate *obj = [arrayDates objectAtIndex:i];
if([obj isEqualToDate:currentDate]) {
//This date has some events, we've done up to here.
//Now taking indexes of same objects (that's same dates objects) from the arrayEvents
NSIndexSet *indexesOfObjects = [arrayDates indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
return [arrayEvents containsObject:obj];
}];
if([indexesOfObjects count] > 1) {
//We found some objects into arrayEvents, now I have to update
//those objects into arrayEvents.
//How to achieve this?
//My plan was to iterate each indexes and make update on arrayEvents
//but I can't do this, as I don't have access to each index from NSIndexSet.
}
}
}
[[arrayEvents objectsAtIndexes:indexesOfObjects]
setValue:[arrayDates objectAtIndex:i] forKey:@"filter_date"];
不工作。
参考,如何指示 NSIndexSet 对象的索引?但对我没有帮助。