Removes the objects at the specified indexes from the array.
SDKs
- iOS 2.0+
- macOS 10.4+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
- (void)removeObjectsAtIndexes:(NSIndex Set *)indexes;
Parameters
indexes
The indexes of the objects to remove from the array. The locations specified by
indexes
must lie within the bounds of the array.
Discussion
This method is similar to remove
, but allows you to efficiently remove multiple objects with a single operation. indexes
specifies the locations of objects to be removed given the state of the array when the method is invoked, as illustrated in the following example:
NSMutableArray *array = [NSMutableArray arrayWithObjects: @"one", @"a", @"two", @"b", @"three", @"four", nil];
NSMutableIndexSet *indexes = [NSMutableIndexSet indexSetWithIndex:1];
[indexes addIndex:3];
[array removeObjectsAtIndexes:indexes];
NSLog(@"array: %@", array);
// Output: array: (one, two, three, four)
If indexes
is nil
, this method raises an exception.