我有一个主数组(arrayEvents
)包含具有start_date,event_id,event_name等字段的事件列表,可以在相同日期但不同时间执行许多事件。所以我只选择唯一的日期(arrayDates
)来检查并将其与当前日期(currentDate
从1月的第1天到月的最后一天的范围)进行比较,以显示特定日期的事件。我已经到了这里。现在我的问题是,我需要更新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"];
没有用。
参考,How to indicate index of NSIndexSet object?,但对我没有帮助。
答案 0 :(得分:0)
您可以尝试这样做:
NSMutableDictionary *dict=[[NSMutableDictionary alloc]initWithDictionary:[arrayEvents objectAtIndex:indexPath.row]];
[dict setValue:[arrayDates objectAtIndex:i] forKey:@"filter_date"];
[arrayEvents replaceObjectAtIndex:indexPath.row withObject:dict];
或者您可以使用
replaceObjectsAtIndexes:(NSIndexSet *) withObjects:(NSArray *)a
哪个适合您的方便