Instance Method


Removes the objects at the specified indexes from the array.


func removeObjects(at indexes: IndexSet)



The indexes of the objects to remove from the array. The locations specified by indexes must lie within the bounds of the array.


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.

See Also

Removing Objects

func removeAllObjects()

Empties the array of all its elements.

func removeLastObject()

Removes the object with the highest-valued index in the array

func remove(Any)

Removes all occurrences in the array of a given object.

func remove(Any, in: NSRange)

Removes all occurrences within a specified range in the array of a given object.

func removeObject(at: Int)

Removes the object at index .

func removeObject(identicalTo: Any)

Removes all occurrences of a given object in the array.

func removeObject(identicalTo: Any, in: NSRange)

Removes all occurrences of anObject within the specified range in the array.

func removeObjects(fromIndices: UnsafeMutablePointer<Int>, numIndices: Int)

Removes the specified number of objects from the array, beginning at the specified index.

func removeObjects(in: [Any])

Removes from the receiving array the objects in another given array.

func removeObjects(in: NSRange)

Removes from the array each of the objects within a given range.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software