<!--
{
  "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/NSMutableString",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMutableString"
  },
  "title" : "NSMutableString"
}
-->

# NSMutableString

A dynamic plain-text Unicode string object.

```
class NSMutableString
```

## Overview

In Swift, you can use this type instead of a <doc://com.apple.documentation/documentation/Swift/String> in cases that require reference semantics.

The `NSMutableString` class declares the programmatic interface to an object that manages a mutable string—that is, a string whose contents can be edited—that conceptually represents an array of Unicode characters. To construct and manage an immutable string—or a string that cannot be changed after it has been created—use an object of the [`NSString`](/documentation/Foundation/NSString) class.

The `NSMutableString` class adds one primitive method—[`replaceCharacters(in:with:)`](/documentation/Foundation/NSMutableString/replaceCharacters(in:with:))—to the basic string-handling behavior inherited from `NSString`. All other methods that modify a string work through this method. For example, [`insert(_:at:)`](/documentation/Foundation/NSMutableString/insert(_:at:)) simply replaces the characters in a range of `0` length, while [`deleteCharacters(in:)`](/documentation/Foundation/NSMutableString/deleteCharacters(in:)) replaces the characters in a given range with no characters.

NSMutableString is “toll-free bridged” with its Core Foundation counterpart, <doc://com.apple.documentation/documentation/CoreFoundation/CFMutableString>. 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.

## Topics

### Creating and Initializing a Mutable String

[`+  stringWithCapacity:`](/documentation/Foundation/NSMutableString/stringWithCapacity:)

Returns an empty `NSMutableString` object with initial storage for a given number of characters.

[`-  initWithCapacity:`](/documentation/Foundation/NSMutableString/init(capacity:))

Returns an `NSMutableString` object initialized with initial storage for a given number of characters,

### Modifying a String

[`-  appendFormat:`](/documentation/Foundation/NSMutableString/appendFormat:)

Adds a constructed string to the receiver.

[`-  appendString:`](/documentation/Foundation/NSMutableString/append(_:))

Adds to the end of the receiver the characters of a given string.

[`-  applyTransform:reverse:range:updatedRange:`](/documentation/Foundation/NSMutableString/applyTransform(_:reverse:range:updatedRange:))

Transliterates the receiver by applying a specified ICU string transform.

[`-  deleteCharactersInRange:`](/documentation/Foundation/NSMutableString/deleteCharacters(in:))

Removes from the receiver the characters in a given range.

[`-  insertString:atIndex:`](/documentation/Foundation/NSMutableString/insert(_:at:))

Inserts into the receiver the characters of a given string at a given location.

[`-  replaceCharactersInRange:withString:`](/documentation/Foundation/NSMutableString/replaceCharacters(in:with:))

Replaces the characters from `range` with those in `aString`.

[`-  replaceOccurrencesOfString:withString:options:range:`](/documentation/Foundation/NSMutableString/replaceOccurrences(of:with:options:range:))

Replaces all occurrences of a given string in a given range with another given string, returning the number of replacements.

[`-  setString:`](/documentation/Foundation/NSMutableString/setString(_:))

Replaces the characters of the receiver with those in a given string.

### Constants

[String Transformations](/documentation/Foundation/string-transformations)

These constants specify transforms used by the [`applyTransform(_:reverse:range:updatedRange:)`](/documentation/Foundation/NSMutableString/applyTransform(_:reverse:range:updatedRange:)) method.

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

### Inherits From

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

---

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)