1. 程式人生 > >NSMutableArray與NSMutableIndexSet結合刪除NSMutableArray中符合條件的object

NSMutableArray與NSMutableIndexSet結合刪除NSMutableArray中符合條件的object

    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];
    }