---
title: NSMutableSet
framework: foundation
role: symbol
role_heading: Class
path: foundation/nsmutableset
---

# NSMutableSet

A dynamic unordered collection of unique objects.

## Declaration

```swift
class NSMutableSet
```

## Overview

Overview You can use this type in Swift instead of a Set in cases that require reference semantics. The NSMutableSet class declares the programmatic interface to a mutable, unordered collection of distinct objects. The NSCountedSet class, which is a concrete subclass of NSMutableSet, supports mutable sets that can contain multiple instances of the same element. The NSSet class supports creating and managing immutable sets. NSMutableSet is “toll-free bridged” with its Core Foundation counterpart, CFMutableSet. See Toll-Free Bridging for more information. Subclassing Notes There should be little need of subclassing. If you need to customize behavior, it is often better to consider composition instead of subclassing. Methods to Override In a subclass, you must override both of its primitive methods: add(_:) remove(_:) You must also override the primitive methods of the NSSet class.

## Topics

### Creating a mutable set

- [init(capacity:)](foundation/nsmutableset/init(capacity:).md)
- [init()](foundation/nsmutableset/init().md)

### Adding and removing entries

- [add(_:)](foundation/nsmutableset/add(_:).md)
- [filter(using:)](foundation/nsmutableset/filter(using:).md)
- [remove(_:)](foundation/nsmutableset/remove(_:).md)
- [removeAllObjects()](foundation/nsmutableset/removeallobjects().md)
- [addObjects(from:)](foundation/nsmutableset/addobjects(from:).md)

### Combining and recombining sets

- [union(_:)](foundation/nsmutableset/union(_:).md)
- [minus(_:)](foundation/nsmutableset/minus(_:).md)
- [intersect(_:)](foundation/nsmutableset/intersect(_:).md)
- [setSet(_:)](foundation/nsmutableset/setset(_:).md)

### Initializers

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

## Relationships

### Inherits From

- [NSSet](foundation/nsset.md)

### Inherited By

- [NSCountedSet](foundation/nscountedset.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)
