<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSMutableCharacterSet",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMutableCharacterSet"
  },
  "title" : "NSMutableCharacterSet"
}
-->

# NSMutableCharacterSet

An object representing a mutable set of Unicode character values for use in search operations.

```
class NSMutableCharacterSet
```

## Overview

In Swift, this object bridges to [`CharacterSet`](/documentation/Foundation/CharacterSet); use [`NSMutableCharacterSet`](/documentation/Foundation/NSMutableCharacterSet) when you need reference semantics or other Foundation-specific behavior.

The `NSMutableCharacterSet` class declares the programmatic interface to objects that manage a modifiable set of Unicode characters. You can add or remove characters from a mutable character set as numeric values in `NSRange` structures or as character values in strings, combine character sets by union or intersection, and invert a character set.

Mutable character sets are less efficient to use than immutable character sets. If you don’t need to change a character set after creating it, create an immutable copy with `copy` and use that.

`NSMutableCharacterSet` defines no primitive methods. Subclasses must implement all methods declared by this class in addition to the primitives of [`NSCharacterSet`](/documentation/Foundation/NSCharacterSet). They must also implement [`mutableCopy(with:)`](/documentation/Foundation/NSMutableCopying/mutableCopy(with:)).

`NSMutableCharacterSet` is “toll-free bridged” with its Core Foundation counterpart, <doc://com.apple.documentation/documentation/CoreFoundation/CFMutableCharacterSet>. See [Toll-Free Bridging](https://developer.apple.com/library/archive/documentation/General/Conceptual/CocoaEncyclopedia/Toll-FreeBridgin/Toll-FreeBridgin.html#//apple_ref/doc/uid/TP40010810-CH2) for more information.

> Important:
> The Swift overlay to the Foundation framework provides the ``doc://com.apple.foundation/documentation/Foundation/CharacterSet`` structure, which bridges to the ``doc://com.apple.foundation/documentation/Foundation/NSMutableCharacterSet`` class and its immutable superclass, ``doc://com.apple.foundation/documentation/Foundation/NSCharacterSet``.  For more information about value types, see <doc://com.apple.documentation/documentation/Swift/working-with-foundation-types>.

## Topics

### Getting Standard Character Sets

[`+  alphanumericCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/alphanumeric())

Returns a character set containing the characters in Unicode General Categories L*, M*, and N*.

[`+  capitalizedLetterCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/capitalizedLetter())

Returns a character set containing the characters in Unicode General Category Lt.

[`+  controlCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/control())

Returns a character set containing the characters in Unicode General Category Cc and Cf.

[`+  decimalDigitCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/decimalDigit())

Returns a character set containing the characters in the category of decimal numbers.

[`+  decomposableCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/decomposable())

Returns a character set containing individual Unicode characters that can also be represented as composed character sequences (such as for letters with accents), by the definition of “standard decomposition” in version 3.2 of the Unicode character encoding standard.

[`+  illegalCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/illegal())

Returns a character set containing values in the category of Non-Characters or that have not yet been defined in version 3.2 of the Unicode standard.

[`+  letterCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/letter())

Returns a character set containing the characters in Unicode General Category L* & M*.

[`+  lowercaseLetterCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/lowercaseLetter())

Returns a character set containing the characters in Unicode General Category Ll.

[`+  newlineCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/newline())

Returns a character set containing the newline characters (`U+000A` ~ `U+000D`, `U+0085`, `U+2028`, and `U+2029`).

[`+  nonBaseCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/nonBase())

Returns a character set containing the characters in Unicode General Category M*.

[`+  punctuationCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/punctuation())

Returns a character set containing the characters in Unicode General Category P*.

[`+  symbolCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/symbol())

Returns a character set containing the characters in Unicode General Category S*.

[`+  uppercaseLetterCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/uppercaseLetter())

Returns a character set containing the characters in Unicode General Category Lu and Lt.

[`+  whitespaceAndNewlineCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/whitespaceAndNewline())

Returns a character set containing characters in Unicode General Category Z*, `U+000A` ~ `U+000D`, and `U+0085`.

[`+  whitespaceCharacterSet`](/documentation/Foundation/NSMutableCharacterSet/whitespace())

Returns a character set containing the characters in Unicode General Category Zs and `CHARACTER TABULATION` (`U+0009`).

### Creating Custom Character Sets

[`+  characterSetWithCharactersInString:`](/documentation/Foundation/NSMutableCharacterSet/init(charactersIn:))

Returns a character set containing the characters in a given string.

[`+  characterSetWithRange:`](/documentation/Foundation/NSMutableCharacterSet/init(range:))

Returns a character set containing characters with Unicode values in a given range.

[`+  characterSetWithBitmapRepresentation:`](/documentation/Foundation/NSMutableCharacterSet/init(bitmapRepresentation:))

Returns a character set containing characters determined by a given bitmap representation.

[`+  characterSetWithContentsOfFile:`](/documentation/Foundation/NSMutableCharacterSet/init(contentsOfFile:))

Returns a character set read from the bitmap representation stored in the file a given path.

### Adding and Removing Characters

[`-  addCharactersInRange:`](/documentation/Foundation/NSMutableCharacterSet/addCharacters(in:)-4ppyw)

Adds to the receiver the characters whose Unicode values are in a given range.

[`-  removeCharactersInRange:`](/documentation/Foundation/NSMutableCharacterSet/removeCharacters(in:)-70nqp)

Removes from the receiver the characters whose Unicode values are in a given range.

[`-  addCharactersInString:`](/documentation/Foundation/NSMutableCharacterSet/addCharacters(in:)-7q02)

Adds to the receiver the characters in a given string.

[`-  removeCharactersInString:`](/documentation/Foundation/NSMutableCharacterSet/removeCharacters(in:)-762gt)

Removes from the receiver the characters in a given string.

### Combining Character Sets

[`-  formIntersectionWithCharacterSet:`](/documentation/Foundation/NSMutableCharacterSet/formIntersection(with:))

Modifies the receiver so it contains only characters that exist in both the receiver and another set.

[`-  formUnionWithCharacterSet:`](/documentation/Foundation/NSMutableCharacterSet/formUnion(with:))

Modifies the receiver so it contains all characters that exist in either the receiver or another set.

### Inverting a Character Set

[`-  invert`](/documentation/Foundation/NSMutableCharacterSet/invert())

Replaces all the characters in the receiver with all the characters it didn’t previously contain.

## Relationships

### Inherits From

[`NSCharacterSet`](/documentation/Foundation/NSCharacterSet)

### Conforms To

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Equatable`](/documentation/Swift/Equatable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Sendable`](/documentation/Swift/Sendable)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`NSMutableCopying`](/documentation/Foundation/NSMutableCopying)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)