removeObjects(at:)
Removes the objects at the specified indexes from the array.
Declaration
func removeObjects(at indexes: IndexSet)Parameters
- indexes:
The indexes of the objects to remove from the array. The locations specified by
indexesmust lie within the bounds of the array.
Discussion
This method is similar to removeObject(at:), 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.