Class

NSMutableCharacterSet

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.

Overview

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. They must also implement mutableCopy(with:).

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

Symbols

Adding and removing characters

func addCharacters(in: NSRange)

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

func removeCharacters(in: NSRange)

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

func addCharacters(in: String)

Adds to the receiver the characters in a given string.

func removeCharacters(in: String)

Removes from the receiver the characters in a given string.

Combining character sets

func formIntersection(with: CharacterSet)

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

func formUnion(with: CharacterSet)

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

Inverting a character set

func invert()

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