NSMutableArray與NSMutableIndexSet結合刪除NSMutableArray中符合條件的object
阿新 • • 發佈:2019-01-27
NSMutableArray *mutable = [NSMutableArray arrayWithArray:searchFlightsHistoryArray];
//過期日期搜尋記錄去重
NSMutableIndexSet *indexSet = [[NSMutableIndexSet alloc] init];
for (int i = 0; i < mutable.count; i++) {
SearchFlightsHistory *indexData = mutable[i];
NSInteger diffDate = [NSDate dayIntervalWithADate:[NSDate date] BDate:indexData.departDate];
if (diffDate < 0) {
[indexSet addIndex:i];
}
}
if (indexSet.count >0) {
[mutable removeObjectsAtIndexes:indexSet];
}
//過期日期搜尋記錄去重
NSMutableIndexSet *indexSet = [[NSMutableIndexSet alloc] init];
for (int i = 0; i < mutable.count; i++) {
SearchFlightsHistory *indexData = mutable[i];
NSInteger diffDate = [NSDate dayIntervalWithADate:[NSDate date] BDate:indexData.departDate];
if (diffDate < 0) {
[indexSet addIndex:i];
}
}
if (indexSet.count >0) {
[mutable removeObjectsAtIndexes:indexSet];
}