How to remove NSDate objects from a NSMutableArray
        Posted  
        
            by 
                Ryan
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Ryan
        
        
        
        Published on 2012-06-20T21:12:44Z
        Indexed on 
            2012/06/20
            21:16 UTC
        
        
        Read the original article
        Hit count: 169
        
I have been working with NSArrays and NSMutableArrays that store NSDate objects for a few days now. I noticed that calling [listOfDates removeObject:date1] removes all the NSDate objects from the array. I have instead been doing this to remove objects:
  NSMutableArray *dateList; // Has Dates in it
  NSDate *dateToRemove;     // Date Object to Remove
  __block NSUInteger indexToRemove;
  __block BOOL       foundMatch = NO;
  [dateList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    if ([obj isEqualToDate:dateToRemove]) {
      indexToRemove = idx;
      foundMatch = YES;
      *stop = YES;
     }
  }];
  if (foundMatch) {
    [dateList removeObjectAtIndex:indexToRemove];
  }
Is there a better way to be doing this? Perhaps another data structure? Or a simpler function?
© Stack Overflow or respective owner