几天来,我一直在使用NSArray
s 和NSMutableArray
s 来存储对象。NSDate
我注意到调用会从数组[listOfDates removeObject:date1]
中删除所有对象。NSDate
相反,我一直在这样做以删除对象:
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];
}
有没有更好的方法来做到这一点?也许是另一种数据结构?还是更简单的功能?