【发布时间】:2014-07-23 11:59:07
【问题描述】:
我有一个主数组 (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"];
没用。
参考,How to indicate index of NSIndexSet object? 但对我没有帮助。
【问题讨论】:
标签: ios nsmutablearray comparison nsdictionary nsindexset