动态修改可变数组元素
1、
NSMutableArray<NSString *> *array = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", @"4", nil]; for (NSString *str in array.reverseObjectEnumerator) { NSLog(@"%@", str); if ([str isEqualToString:@"2"]) { [array removeObject:str]; } }
2、
NSMutableArray<NSString *> *array = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", @"4", nil]; [array enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj isEqualToString:@"2"]) { [array removeObject:obj]; } }];
参考:
http://weibo.com/touristdiary?refer_flag=1005055013_&is_all=1#_rnd1468202765617