---
title: NSMutableArray
framework: foundation
role: symbol
role_heading: Class
path: foundation/nsmutablearray
---

# NSMutableArray

A dynamic ordered collection of objects.

## Declaration

```swift
class NSMutableArray
```

## Overview

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: insert(_:at:) removeObject(at:) add(_:) removeLastObject() replaceObject(at:with:) 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

- [init(contentsOfURL:)](foundation/nsmutablearray/init(contentsofurl:).md)
- [init()](foundation/nsmutablearray/init().md)
- [init(capacity:)](foundation/nsmutablearray/init(capacity:).md)

### Adding Objects

- [add(_:)](foundation/nsmutablearray/add(_:).md)
- [addObjects(from:)](foundation/nsmutablearray/addobjects(from:).md)
- [insert(_:at:)](foundation/nsmutablearray/insert(_:at:)-5dbx5.md)
- [insert(_:at:)](foundation/nsmutablearray/insert(_:at:)-73pln.md)

### Removing Objects

- [removeAllObjects()](foundation/nsmutablearray/removeallobjects().md)
- [removeLastObject()](foundation/nsmutablearray/removelastobject().md)
- [remove(_:)](foundation/nsmutablearray/remove(_:).md)
- [remove(_:in:)](foundation/nsmutablearray/remove(_:in:).md)
- [removeObject(at:)](foundation/nsmutablearray/removeobject(at:).md)
- [removeObjects(at:)](foundation/nsmutablearray/removeobjects(at:).md)
- [removeObject(identicalTo:)](foundation/nsmutablearray/removeobject(identicalto:).md)
- [removeObject(identicalTo:in:)](foundation/nsmutablearray/removeobject(identicalto:in:).md)
- [removeObjects(fromIndices:numIndices:)](foundation/nsmutablearray/removeobjects(fromindices:numindices:).md)
- [removeObjects(in:)](foundation/nsmutablearray/removeobjects(in:)-4yb26.md)
- [removeObjects(in:)](foundation/nsmutablearray/removeobjects(in:)-1udmn.md)

### Replacing Objects

- [replaceObject(at:with:)](foundation/nsmutablearray/replaceobject(at:with:).md)
- [replaceObjects(at:with:)](foundation/nsmutablearray/replaceobjects(at:with:).md)
- [replaceObjects(in:withObjectsFrom:range:)](foundation/nsmutablearray/replaceobjects(in:withobjectsfrom:range:).md)
- [replaceObjects(in:withObjectsFrom:)](foundation/nsmutablearray/replaceobjects(in:withobjectsfrom:).md)
- [setArray(_:)](foundation/nsmutablearray/setarray(_:).md)

### Filtering Content

- [filter(using:)](foundation/nsmutablearray/filter(using:).md)

### Rearranging Content

- [exchangeObject(at:withObjectAt:)](foundation/nsmutablearray/exchangeobject(at:withobjectat:).md)
- [sort(using:)](foundation/nsmutablearray/sort(using:)-4eh07.md)
- [sort(comparator:)](foundation/nsmutablearray/sort(comparator:).md)
- [sort(options:usingComparator:)](foundation/nsmutablearray/sort(options:usingcomparator:).md)
- [sort(_:context:)](foundation/nsmutablearray/sort(_:context:).md)
- [sort(using:)](foundation/nsmutablearray/sort(using:)-537vs.md)

### Initializers

- [init(coder:)](foundation/nsmutablearray/init(coder:).md)
- [init(objects:count:)](foundation/nsmutablearray/init(objects:count:).md)

### Default Implementations

- [NSMutableArray Implementations](foundation/nsmutablearray/nsmutablearray-implementations.md)

## Relationships

### Inherits From

- [NSArray](foundation/nsarray.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomReflectable](swift/customreflectable.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [ExpressibleByArrayLiteral](swift/expressiblebyarrayliteral.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSFastEnumeration](foundation/nsfastenumeration.md)
- [NSMutableCopying](foundation/nsmutablecopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [Sequence](swift/sequence.md)
