Contents

NSMutableArray

A dynamic ordered collection of objects.

Declaration

class NSMutableArray

Overview

You can use this type in Swift instead of an Array variable in cases that require reference semantics.

The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects. This class adds insertion and deletion operations to the basic array-handling behavior inherited from NSArray.

NSMutableArray is “toll-free bridged” with its Core Foundation counterpart, CFMutableArray. See Toll-Free Bridging for more information.

Accessing Values Using Subscripting

In addition to the provided instance methods, such as replaceObject(at:with:), you can access NSArray values by their indexes using subscripting.

Subclassing Notes

There is typically little reason to subclass NSMutableArray. The class does well what it is designed to do—maintain a mutable, ordered collection of objects. But there are situations where a custom NSArray object might come in handy. Here are a few possibilities:

  • Changing how NSMutableArray stores the elements of its collection. You might do this for performance reasons or for better compatibility with legacy code.

  • Acquiring more information about what is happening to the collection (for example, statistics gathering).

Methods to Override

NSMutableArray defines five primitive methods:

In a subclass, you must override all these methods. You must also override the primitive methods of the NSArray class.

Topics

Creating and Initializing a Mutable Array

Adding Objects

Removing Objects

Replacing Objects

Filtering Content

Rearranging Content

Initializers

Default Implementations